app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/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, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
1 回答
1.如何验证身份验证令牌(cookie)?
Ans:您可以在App_Start文件夹中找到实现此逻辑的Startup.Auth.cs文件:
app.UseCookieAuthenticatin使您的应用程序可以使用cookieAuthention并验证cookie,您也可以创建自己的逻辑来验证您的cookie .
Ans:它忽略了已过期的cookie,您可以使用以下代码在CookieAuthenticationOptions中定义Cookie的过期时间:
ExpireTimeSpan = TimeSpan.FromHours(1),