MVC5空引用与Facebook登录 [英] MVC5 Null Reference with facebook login

查看:197
本文介绍了MVC5空引用与Facebook登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Im getting an null reference exception sometimes when I login with facebook using the out of the box ASP.NET mvc5 accounts controller.

下面是dieing方式:

Here is the dieing method :

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


林不知道如何调试这一点。一个断点,并浸泡虽然code是没有帮助......我最后看着我Error.cshtml页面。在这一点上的错误是一个简单的对象引用无效异常,内部异常也为空。


Im not sure how to debug this. A breakpoint and steeping though the code is no help... I end up looking at my Error.cshtml page. The error at that point is a simple object reference null exception and the inner exception is also null.

修改

我更新通过的NuGet最新Owins,没有任何变化。

I updated to the latest Owins via Nuget, no change.

编辑2

参加了小提琴手一看,Facebook正在与返回什么看起来像一个正确的配置文件为JSON 200。

Took a look in fiddler, Facebook is returning a 200 with what looks like a correct profile as json.

修改3

太奇怪了。 3 Facebook账户IM测试。两个帐户做工精细,1没有。失败的一个是与200回我已删除了Facebook应用程序引用..我得到一个应用程序确认窗口,我点击确定,它死....太奇怪了。

So strange. Im testing with 3 facebook accounts. Two accounts are working fine, 1 does not. The failing one is returning with 200. I have removed the app references in facebook.. I get a app confirmation window, I click ok, and it dies.... so strange.

推荐答案

现在一个快速的解决方案。

A quick solution for now.

您必须ExternalLoginCallback之前清除会话。例子。

You have to clear the Session before ExternalLoginCallback. Example.

[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 }));
}

这篇关于MVC5空引用与Facebook登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆