SPContext.currentはiHttphandlerの場合はNULLです
-
10-12-2019 - |
質問
SharePoint 2010でiHttphandlerを実装しようとしています。-asp-net-httphandler-to-sharepoint-2010.aspx "> http://blogs.msn.com/b/kaevans/archive / 2010/08/04/deploying-an-asp-net-httphandler-to-SharePoint-2010.aspx
しかし、私はspcontext.currentを取得しています.currentは "null"で、コンテキストサイトを取得できません。
URLは次のようなものです。
http://spsvr/sitecoll/subsite/_layouts/myfolder/myhandler.ashx?param1=paramvalue
. 解決
私は私の質問に答えています。
@Simondoyをレビューした後、「それは奇妙な」と私が本当に間違いをしてから間違いを実現していることに気づいています。
私は間違った、私は昇格した許可を持って走っていて、私はspcontext.currentを参照していました。
エラーコード
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
}
}
});
}
. 所属していません sharepoint.stackexchange