我整晚都在摸着头,用谷歌搜索,但似乎没有什么对我有用。当尝试使用Facebook登录我的mvc5应用程序时,我继续在AuthenticationManager.GetExternalLoginInfoAsync()中获取空引用错误。使用Google登录效果非常好。
这是我的设置:
https://localhost:44302/
(注意:Google无论如何都能正常工作)。注意:我使用的是mvc5中的默认设置/模板,没有更改任何内容 - 当然除了用于fb的AppId和AppSecret。
任何人都可以投入一些解决方案。感谢。
答案 0 :(得分:1)
替换var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
通过此代码:
var result = await AuthenticationManager.AuthenticateAsync(DefaultAuthenticationTypes.ExternalCookie);
if (result == null || result.Identity == null)//here will check if user login done
{
return RedirectToAction("Login");
}
var idClaim = result.Identity.FindFirst(ClaimTypes.NameIdentifier);
if (idClaim == null)
{
return RedirectToAction("Login");
}
var login = new UserLoginInfo(idClaim.Issuer, idClaim.Value);//here getting login info
var name = result.Identity.Name == null ? "" : result.Identity.Name.Replace(" ", "");//here getting user name