使用facebook登录MVC5 Null参考

nVe*_*lia 21 c# asp.net asp.net-mvc facebook

当我使用开箱即用的ASP.NET mvc5帐户控制器登录Facebook时,我有时会得到一个空引用异常.


这是节食方法:

public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
        // Crashes on this line
        var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
        if (loginInfo == null)
        {
            return RedirectToAction("Login");
        }
}
Run Code Online (Sandbox Code Playgroud)

我不知道如何调试这个.一个断点和浸泡虽然代码没有帮助...我最终看到我的Error.cshtml页面.此时的错误是一个简单的对象引用null异常,内部异常也是null.


编辑

我通过Nuget更新到最新的Owins,没有变化.

编辑2

看看小提琴手,Facebook正在回归200,看起来像json一样正确.

编辑3

这么奇怪.我正在测试3个Facebook帐户.两个帐户工作正常,1个没有.失败者返回200.我已经删除了Facebook中的应用程序引用..我得到一个应用程序确认窗口,我点击确定,它死了......太奇怪了.

Lee*_*Lee 34

现在快速解决方案.

您必须在ExternalLoginCallback之前清除会话.例.

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult ExternalLogin(string provider, string returnUrl)
{
    ControllerContext.HttpContext.Session.RemoveAll();

    // Request a redirect to the external login provider
    return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }));
}
Run Code Online (Sandbox Code Playgroud)


小智 6

将我的Owin组件从版本3.0.1升级到版本3.1.0修复了此问题(到目前为止).3.1.0于2017年4月10日发布.