[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
is the message I'm getting when I deploy my website online.
Locally everything is running fine, even when I copy all project files to another computer everything shows fine.
However, when I publish the site to the IIS server it shows the error as displayed above.
Are the any settings which I could be missing?
I doubt this is a coding issue as everything works perfectly on the localhost
code in 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;
}"
Additional code for 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;
}
}
getCookieContainerisnulland you're trying to do something with it. CangetSamlToken();returnnull? If so then accessingcookies.FedAuthwill break - use that as an example and check things aren't nothing (i.e.if (something != null).Could not load file or assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.