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

是我在线部署网站时收到的消息。

本地一切运行良好,即使我将所有项目文件复制到另一台计算机,一切都显示正常。

但是,当我将站点发布到 IIS 服务器时,它会显示如上所示的错误。

是否有我可能缺少的任何设置?我怀疑这是一个编码问题,因为一切都在localhost

Default.aspx.cs 中的代码:

  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;
            }"

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;
        }
    }
4

2 回答 2

2

Microsoft.EntityModel.dll 未在发布时添加到服务器上。我已经手动将此 .dll 放在服务器上,现在它可以工作了。

感谢您的帮助格兰特托马斯。

于 2012-11-01T14:42:26.347 回答
0

它实际上是带有路径的 Microsoft.IdentityModel 参考:

C:\Program Files\Reference Assemblies\Microsoft\Windows Identity Foundation\v3.5\Microsoft.IdentityModel.dll

如果你安装了 VS

于 2014-12-23T09:10:27.830 回答