//错误的写法
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
            }
        }
    });

}

 

相关文章:

  • 2022-12-23
  • 2021-07-03
  • 2021-08-21
  • 2022-12-23
  • 2021-07-14
  • 2021-06-23
  • 2021-09-15
  • 2022-12-23
猜你喜欢
  • 2021-12-29
  • 2021-08-01
  • 2021-11-27
  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
  • 2021-07-13
相关资源
相似解决方案