因为经常需要提升权限来完成一件事情,特此封装为一个固定的方法来调用。
protected void RunWithElevatedPrivilegesAndContextSwitch(SPSecurity.CodeToRunElevated secureCode)
{
HttpContext backupContext = HttpContext.Current;
HttpContext.Current = null;
SPSecurity.RunWithElevatedPrivileges(secureCode);
HttpContext.Current = backupContext;
}