我正在尝试在Visual Studio 2013中的新MVC 5项目中设置集成的OWIN Facebook身份验证.我已根据本教程配置了应用程序和密钥:
但是,我在AccountController中从此调用中抛出了NullReferenceException:
[AllowAnonymous]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
Run Code Online (Sandbox Code Playgroud)
我已经检查了Fiddler的回复,并且得到了Facebook的成功回复,但仍然得到了这个错误.响应如下:
{"id":"xxx","name":"xxx","first_name":"xxx","last_name":"xxx","link":
"https:\/\/www.facebook.com\/profile.php?id=xxx","location":{"id":"xxx","name":"xxx"},
"gender":"xxx","timezone":1,"locale":"en_GB","verified":true,"updated_time":"2013-10-23T10:42:23+0000"}
Run Code Online (Sandbox Code Playgroud)
我在http和https中进行调试时得到了这个.我猜这是一个框架错误,但迄今为止通过反射器诊断出这一点.
我安装了昨天发布的VS2013最终位,我正试图在我启用外部Facebook登录的地方工作.我的第一个问题:
在这个控制器代码中(我没有触摸并保留原样来自示例模板):
//
// GET: /Account/ExternalLoginCallback
[AllowAnonymous]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
return RedirectToAction("Login");
}
Run Code Online (Sandbox Code Playgroud)
我在行上设置断点等待AuthenticationManager.GetExternalLoginInfoAsync().代码返回(在我登录Facebook之后),"loginInfo"为null.在UI中,继续显示登录页面,不做任何更改.我该怎么调试呢?我试图找到GetExternalLoginInfoAsync()内部的代码,但根据这个线程:
Asp.Net Identity RTM版本中的Microsoft.AspNet.Identity.Owin.AuthenticationManager在哪里?
AuthenticationManager现在已经不存在了.(上面似乎并非如此.)
我的第二个问题:是否有其他人能够使用Facebook登录而不更改ASP.NET MVC5示例代码(除了取消注释app.UseFacebookAuthentication并填写您的FB应用程序详细信息)?(您必须使用Facebook配置别名主机,例如"localtest.me",并使用IIS express配置它.)
谢谢你的帮助...
-ben
我在使用ASP.NET身份的ASP.NET MVC5应用程序中遇到OWIN OpenId提供程序的问题,并且基于具有个人用户帐户身份验证的VS2013模板.用于Google和LinkedIn的OWIN OpenID提供程序用于登录身份验证.
问题是看起来很随机; 即使登录验证成功,GetExternalLoginInfo()也会在LoginConfirmation回调中返回null.
var authManager = HttpContext.Current.GetOwinContext().Authentication;
var login = authManager.GetExternalLoginInfo();
Run Code Online (Sandbox Code Playgroud)
使用的提供商是Google(Microsoft.Owin.Security.Google 2.1.0)和LinkedIn(来自Owin.Security.Providers 1.3),两家提供商都会导致同样的问题.
有时它失败一次然后再次工作,但有时它会继续失败,直到AppPool被回收.
目前,应用程序的两个实例托管在同一Windows Azure虚拟机上的IIS中.每个实例都有自己的AppPool但设置相同(不同的子域).有时登录停止在一个实例上工作,但仍然在另一个实例上工作.
这个问题也在本地重现(IIS Express - VS2013).
任何人都遇到类似的OWIN OpenID身份验证问题?
Startup.Auth.cs看起来像这样:
public void ConfigureAuth(IAppBuilder app)
{
// Enable the application to use a cookie to store information for the signed in user
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
});
// Use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseGoogleAuthentication(); …Run Code Online (Sandbox Code Playgroud)