sharepoint 2010项目中,ashx页面获取SPContext.Current 为null的原因和解决方法
生活随笔
收集整理的這篇文章主要介紹了
sharepoint 2010项目中,ashx页面获取SPContext.Current 为null的原因和解决方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//錯誤的寫法
public void ProcessRequest(HttpContext context)
{SPSecurity.RunWithElevatedPrivileges(delegate{// 'SPContext.Current' null reference errorusing (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
}}});}
?
轉載于:https://www.cnblogs.com/lishidefengchen/p/5480990.html
總結
以上是生活随笔為你收集整理的sharepoint 2010项目中,ashx页面获取SPContext.Current 为null的原因和解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Hadoop的数据管理
- 下一篇: Linux字符设备与块设备的区别与比较