Asp.net [NullReferenceException:对象引用未设置为对象的实例。]
是我在线部署网站时收到的消息 在本地,一切都正常运行,即使我将所有项目文件复制到另一台计算机上,一切都正常 但是,当我将站点发布到IIS服务器时,会显示如上所示的错误 是否有我可能缺少的设置? 我怀疑这是一个编码问题,因为一切都在Asp.net [NullReferenceException:对象引用未设置为对象的实例。],asp.net,sharepoint,nullreferenceexception,Asp.net,Sharepoint,Nullreferenceexception,是我在线部署网站时收到的消息 在本地,一切都正常运行,即使我将所有项目文件复制到另一台计算机上,一切都正常 但是,当我将站点发布到IIS服务器时,会显示如上所示的错误 是否有我可能缺少的设置? 我怀疑这是一个编码问题,因为一切都在localhost上完美运行 Default.aspx.cs中的代码: [NullReferenceException: Object reference not set to an instance of an object.] Wictor.Office365
localhost上完美运行
Default.aspx.cs中的代码:
[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
MsOnlineClaimsHelper的附加代码
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;
}"
发布时未在服务器上添加Microsoft.EntityModel.dll。
我已经将这个.dll手动放在服务器上,现在它可以工作了
感谢您的帮助,GrantThomas。它实际上是Microsoft.IdentityModel引用,路径为:
C:\Program Files\Reference Assembly\Microsoft\Windows Identity
Foundation\v3.5\Microsoft.IdentityModel.dll
如果您安装了VS这里有一些代码,告诉我们您从哪里得到这个错误会很有用。@GrantThomas请参阅第一篇文章,确切的错误在顶部。提前感谢Kay,这会告诉你错误发生的确切位置;这对您来说更容易,因为您在编辑器中有源代码+行计数等。但是getCookieContainer
中的某些内容是null
,您正在尝试对其进行处理。CangetSamlToken()代码>返回null
?如果是这样,那么访问cookies.FedAuth将中断-以它为例,检查事物是否为空(即If(something!=null)
@GrantThomas getSamlToken()引发此异常无法加载文件或程序集“Microsoft.IdentityModel,Version=3.5.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。系统找不到指定的文件。
// 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;
}
}