ASP.NET MVC 5 (VS2013 final): Facebook login with

2019-02-12 17:44发布

I installed the VS2013 final bits that were released yesterday, and I'm trying to get an example working where I enable an external Facebook login. My first question:

In this controller code (which I did not touch and left as is from the sample template):

    //
    // GET: /Account/ExternalLoginCallback
    [AllowAnonymous]
    public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
    {
        var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
        if (loginInfo == null)
        {
            return RedirectToAction("Login");
        }

I set a breakpoint on the line await AuthenticationManager.GetExternalLoginInfoAsync(). The code returns (after I do my Facebook login), and "loginInfo" is null. In the UI, the login page continues to be displayed, with no change. How can I debug this? I was trying to find the code inside of GetExternalLoginInfoAsync() but according to this thread:

Where is Microsoft.AspNet.Identity.Owin.AuthenticationManager in Asp.Net Identity RTM version?

AuthenticationManager is now gone. (This does not seem to be the case per above.)

My second question: Is anyone else able to get the sample working with Facebook login with no changes to the ASP.NET MVC5 sample code (other than uncommenting app.UseFacebookAuthentication and filling in your FB app details)? (You'll have to configure an alias host with Facebook, such as "localtest.me" and configure it with IIS express.)

Thanks for any help...

-Ben

8条回答
淡お忘
2楼-- · 2019-02-12 18:43

i added microsoft.security.owin.facebook reference to project fron NuGet package manager and it started working fine.

查看更多
够拽才男人
3楼-- · 2019-02-12 18:45

I could see everything working in Fiddler with the info required to populate the loginInfo present but was still getting null returned from GetExternalLoginInfoAsnyc.

When I added the following line to the ConfigureAuth method in Startup.Auth, loginInfo was no longer null.

app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
查看更多
登录 后发表回答