//错误的写法 public void ProcessRequest(HttpContext context) { SPSecurity.RunWithElevatedPrivileges(delegate { // ‘SPContext.Current‘ null reference error using (var site = new SPSite(SPContext.Current.Site.ID)) { using (var web = site.OpenWeb(SPContext.Current.Web.ID)) { // codes goes here } } }); }
//正确的写法 public void ProcessRequest(HttpContext context) { var curSite = SPContext.Current.Site; var curWeb = SPContext.Current.Web; SPSecurity.RunWithElevatedPrivileges(delegate { using (var site = new SPSite(curSite.ID)) { using (var web = site.OpenWeb(curWeb.ID)) { // code goes here } } }); }
时间: 2024-11-01 09:17:23