我在我的NullReferenceException MVC应用程序中找到了一个似乎是导致ASP.NET出现缺陷的缺陷。是我破坏了这个,还是应该破坏大多数安装的DotNetOpenAuth?
我明白了:
[NullReferenceException: Object reference not set to an instance of an object.]
DotNetOpenAuth.AspNet.OpenAuthSecurityManager.GetUsername(HttpContextBase context) +27
DotNetOpenAuth.AspNet.OpenAuthSecurityManager.RequestAuthentication(String returnUrl) +341
Controllers.LoginController.Index() +226这是Index()方法。注意,它当前返回生产中的用户和开发中的OK。这显然是暂时的。注释代码来自我在下面引用的最后一个URL,在那里,我减少了我和问题之间的代码数量。不过,堆栈跟踪仍然是相似的。
public virtual ActionResult Index()
{
if (HttpContext == null) return Content("HttpContext");
if (HttpContext.User == null) return Content("User");
if (HttpContext.User.Identity == null) return Content("Identity");
return Content("OK");
new OpenAuthSecurityManager(HttpContext, s_fbClient, OAuthDataProvider.Instance)
.RequestAuthentication(Url.Action(Actions.Callback()));
// OAuthWebSecurity
// .RequestAuthentication("facebook", Url.Action(Actions.Callback()));
return null;
}出现此异常是因为HttpContext.User为null。图书馆源用于那个失败的方法。
private static string GetUsername(HttpContextBase context) {
string username = null;
if (context.User.Identity.IsAuthenticated) {
username = context.User.Identity.Name;
}
return username ?? string.Empty;
}User显然有自从IIS集成模式可用以来,一直为空。这就解释了为什么我没有看到它在开发中,因为我运行的是IIS的默认值,但它不能解释为什么我找不到任何有关缺陷的信息。集成模式于2007年发布,DotNetOpenAuth仍在维护中。Microsoft文档对设置进行了如下说明:
经典模式:仅当应用程序池中的应用程序无法以集成模式运行时才使用此模式。
我一定是错过了什么,因为似乎每个人都应该有这个问题。
我有没有搞过一个没有维护的图书馆?这似乎很奇怪,因为它显示它是刚刚更新一周前。但是,当我遵循NuGet的文档链接时,我到达的源代码似乎甚至没有一个AspNet名称空间,在这里出现了我的异常。
编辑:我目前使用的唯一相关包是DotNetOpenAuth.AspNet (它有8个依赖项),最近一次发布不到一周。我也试过其他的包裹。我不需要SimpleAuth或任何WebMatrix爵士乐。在解决这个问题的过程中,我尝试了像描述的http://techblog.dorogin.com/2013/06/Microsoft.AspNet.WebPages.OAuth.html那样切换库。
编辑:记录了一个与此相关的缺陷,但这个库似乎无法维护。https://github.com/DotNetOpenAuth/DotNetOpenAuth/issues/317#issuecomment-29580565
编辑:挂起的堆栈跟踪,它可能是与MVC 5 Owin Facebook导致Null引用异常相同的缺陷
发布于 2013-12-02 20:31:39
这确实是DotNetOpenAuth.AspNet代码中的一个缺陷。不幸的是,DotNetOpenAuth库已不再维护。用以下方式修改源:
private static string GetUsername(HttpContextBase context) {
string username = null;
if (context.User != null && context.User.Identity.IsAuthenticated) {
username = context.User.Identity.Name;
}
return username ?? string.Empty;
}当然可以了。
https://stackoverflow.com/questions/20308517
复制相似问题