【发布时间】:2017-08-20 06:45:08
【问题描述】:
我在我的网站中通过 ASP 身份框架使用 Google 和 Facebook 身份验证,两个提供商的外部登录在某些时候工作正常,但有时却不能,我不明白问题出在哪里,但工作正常当我重新启动应用程序时。
System.NullReferenceException:对象引用未设置为对象的实例。 在 Microsoft.AspNet.Identity.Owin.SignInManager`2.d__1d.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 SweetNightsIn.Identity.SiteUserManager.d__14.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 SweetNightsIn.Web.Controllers.AccountController.d__3.MoveNext()
OWIN startup.cs 长这样,
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
app.CreatePerOwinContext(IdentityDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString(AppConstants.LoginPath)
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
FacebookAuthenticationOptions facebookOptions = new FacebookAuthenticationOptions()
{
AppId = ConfigurationManager.AppSettings["FacebookAppId"],
AppSecret = ConfigurationManager.AppSettings["FacebookAppSecret"],
UserInformationEndpoint = "https://graph.facebook.com/v2.8/me?fields=id,name,email",
BackchannelHttpHandler = new FacebookBackChannelHandler()
};
facebookOptions.Scope.Add("email");
app.UseFacebookAuthentication(facebookOptions);
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = ConfigurationManager.AppSettings["GoogleAppId"],
ClientSecret = ConfigurationManager.AppSettings["GoogleAppSecret"],
Caption = "Google +"
});
如果您需要更多信息,请回复
【问题讨论】:
标签: authentication asp.net-identity owin