Tuesday, April 5, 2011

Impersonating using SPUserToken object


using (SPSite site = new SPSite(siteURL))
{
using (SPSite siteAsOtherUser = new SPSite(siteURL, site.RootWeb.AllUsers["WS2003\\Administrator"].UserToken))
{
SPWeb web = siteAsOtherUser.OpenWeb();
//Write code with elevated privilege.
}
}

No comments:

Post a Comment