문제

SharePoint 2010에서 iHttphandler를 구현하려고 노력하고 있습니다. http://blogs.msdn.com/b/kaevans/archive/2010/08/04/deploying-an-asp-net-httphandler-sto-SharePoint-2010.aspx

그러나 spcontext.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
            }
        }
    });

}
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top