我正在使用asp.net標識的asp.net mvc應用程序。
在Startup.Auth.cs
文件中,我將ExpireTimeSpan
設置爲20天,但當我登錄到我的應用程序時,我的應用程序早於20天就被註銷,我必須登錄agian!爲什麼要以比asp.net身份的ExpireTimeSpan更早註銷?
Startup.Auth.cs
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, User>(
validateInterval: TimeSpan.FromMinutes(0),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
},
ExpireTimeSpan = TimeSpan.FromDays(20),
SlidingExpiration = true
});
而在Login
行動:
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: true);
更新
當我登錄,我.AspNet.ApplicationCookie
並且它的過期日期被設置爲「20」天后,並且當我第二天打開網站時,我是註銷,但是Cookie存在。
是什麼這個問題的原因是什麼?
在此先感謝。
將'model.RememberMe'設置爲'true',並確定在調用PasswordSignInAsync時它是'true'? – CodingYoshi
提前多久? – sepehr
@CodingYoshi是的,'RememberMe'設置爲'true',我敢肯定! –