Method 1
//Impersonate the poolWindowsImpersonationContext ctx = null;
ctx = WindowsIdentity.Impersonate(System.IntPtr.Zero);
SPSite site = new SPSite("http://mysteurl");
SPWeb web = site.OpenWeb();
try
{
//All of this code will run with elevated privileges
}
catch (Exception ex)
{}
finally
{
web.Dispose();
//make sure you revert to normal
ctx.Undo();
}
Method 2
//Impersonate the poolSPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite("http://mysteurl"))
{
using (SPWeb web = site.OpenWeb())
{
//All of this code will run with elevated privileges
}
}
});
No comments:
Post a Comment