2012-11-01 5 views
0
[NullReferenceException: Object reference not set to an instance of an object.] 
    Wictor.Office365.MsOnlineClaimsHelper.getCookieContainer() +128 
    Wictor.Office365.MsOnlineClaimsHelper.clientContext_ExecutingWebRequest(Object sender, WebRequestEventArgs e) +33 
    Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest() +382 
    Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() +16 
    Webapplicatie.Default.Page_Load(Object sender, EventArgs e) +334 
    System.Web.UI.Control.LoadRecursive() +70 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3177 

은 온라인 웹 사이트를 배포 할 때 표시되는 메시지입니다.[NullReferenceException : 개체 참조가 개체의 인스턴스로 설정되지 않았습니다.]

모든 프로젝트 파일을 다른 컴퓨터에 모두 복사해도 모든 것이 잘 실행됩니다.

그러나 IIS 서버에 사이트를 게시하면 위에 표시된 오류가 표시됩니다.

누락 될 수있는 설정이 있습니까? MsOnlineClaimsHelper

// Method used to add cookies to CSOM 
    public void clientContext_ExecutingWebRequest(object sender, WebRequestEventArgs e) { 
     e.WebRequestExecutor.WebRequest.CookieContainer = getCookieContainer(); 
     //e.WebRequestExecutor.WebRequest.UserAgent = userAgent; 
    } 

    // Creates or loads cached cookie container 
    CookieContainer getCookieContainer() { 
     if (_cachedCookieContainer == null || DateTime.Now > _expires) { 

      // Get the SAML tokens from SPO STS (via MSO STS) using fed auth passive approach 
      MsoCookies cookies = getSamlToken(); 

      if (!string.IsNullOrEmpty(cookies.FedAuth)) { 

       // Create cookie collection with the SAML token      
       _expires = cookies.Expires; 
       CookieContainer cc = new CookieContainer(); 

       // Set the FedAuth cookie 
       Cookie samlAuth = new Cookie("FedAuth", cookies.FedAuth) { 
        Expires = cookies.Expires, 
        Path = "/", 
        Secure = cookies.Host.Scheme == "https", 
        HttpOnly = true, 
        Domain = cookies.Host.Host 
       }; 
       cc.Add(samlAuth); 


       if (_useRtfa) { 
        // Set the rtFA (sign-out) cookie, added march 2011 
        Cookie rtFa = new Cookie("rtFA", cookies.rtFa) { 
         Expires = cookies.Expires, 
         Path = "/", 
         Secure = cookies.Host.Scheme == "https", 
         HttpOnly = true, 
         Domain = cookies.Host.Host 
        }; 
        cc.Add(rtFa); 
       } 
       _cachedCookieContainer = cc; 
       return cc; 
      } 
      return null; 
     } 
     return _cachedCookieContainer; 
    } 

    public CookieContainer CookieContainer { 
     get { 
      if (_cachedCookieContainer == null || DateTime.Now > _expires) { 
       return getCookieContainer(); 
      } 
      return _cachedCookieContainer; 
     } 
    } 
+1

여기에 약간의 코드가 있습니다.이 오류가 발생하는 곳을 알려 주시면 도움이 될 것입니다. –

+0

@GrantThomas 첫 번째 게시물을 참조하십시오. 정확한 오류가 맨 위에 있습니다. 미리 감사드립니다. – Rob

+1

오케이, 오류는 정확히 어디에서 발생하는지 알려줍니다. 에디터에 줄 수와 줄 수 등이 있기 때문에 더 쉽습니다.하지만'getCookieContainer'의 내용은'null'이며 뭔가를하려고합니다. 'getSamlToken();''null'을 리턴 할 수 있습니까? 그렇다면'cookies.FedAuth'에 접근하는 것은 중단 될 것입니다 - 예제로 사용하고 체크하는 것은 아무 것도 아닙니다 (즉,'if (something! = null)') –

답변

2

Microsoft.EntityModel.dll에 대한

MsOnlineClaimsHelper claimsHelper = new MsOnlineClaimsHelper(sharepointsiteUrl, username, password); 
      using (ClientContext context = new ClientContext(sharepointsiteUrl)) 
      { 
       context.ExecutingWebRequest += claimsHelper.clientContext_ExecutingWebRequest; 

       context.Load(context.Web); 

       context.ExecuteQuery(); 

       Lebel.Text = "Succesfully logged in as " + username + " on " + context.Web.Title; 
      }" 

추가 코드 : 나는 모든하여 default.aspx.cs에서 localhost

코드를 완벽하게 작동하기 때문에이 코딩 문제가 의심 게시 할 때 서버에 추가되지 않았습니다. 이 .dll을 서버에 수동으로 넣었습니다. 이제 작동합니다.

도움 주셔서 감사합니다. GrantThomas.

0

실제로 경로 Microsoft.IdentityModel 참조입니다 :

C : \ 프로그램 파일 \ 참조 어셈블리 \ 마이크로 소프트 \ 윈도우 신원 재단 \의 V3.5 \ Microsoft.IdentityModel.dll

VS가 설치된 경우

관련 문제