我编写了一个网页,该网页使用MVC5和OAuth来利用Google/Facebook身份验证。
有时,我可以使用Facebook或Google进行很好的身份验证。效果很好。
但是,经常发生的是:
我没有收到(或找不到合适的位置)任何提示我的错误-我在Azure上使用SSL进行托管。
有人有提示为什么有时起作用,有时却不起作用吗?感觉好像是cookie的事,还是服务器端的配置问题?我不知道为什么它有时会起作用,有时会不起作用。
我试过了:
出Cookie),同样的问题。
我的配置方式:
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);
// Uncomment the following lines to enable logging in with third party login providers
//app.UseMicrosoftAccountAuthentication(
// clientId: "",
// clientSecret: "");
//app.UseTwitterAuthentication(
// consumerKey: "",
// consumerSecret: "");
app.UseFacebookAuthentication(
appId: "abc",
appSecret: "123");
app.UseGoogleAuthentication();
}
我已按照本教程在MVC5中使用OAuth:Create an ASP.NET MVC 5 App with Facebook, Twitter, LinkedIn and Google OAuth2 Sign-on (C#)
最佳答案
这是一个主要问题,您的应用程序将随机进入无限循环,有时重新部署该应用程序使其可以运行,但只能是临时的。我发现解决此问题的快速方法是使用@cooper注释的nuget包kentor.owincookiesaver
。您应该在owin启动类中的cookieauthentication调用之前调用此类,如下所示
app.UseKentorOwinCookieSaver();
app.UseCookieAuthentication(new CookieAuthenticationOptions());
显然,owin和katana中存在一个错误,您的cookie刚刚消失了,此问题得以解决。
关于asp.net-mvc - 在MVC5中使用OAuth时,无限循环返回到身份验证页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21168686/