【发布时间】:2015-06-08 08:26:07
【问题描述】:
我有一个 Asp.net MVC 网站。当用户更改密码时,是否所有浏览器的登录都无效?我的意思是用户是否需要使用新密码登录所有浏览器?如果没有,有没有办法做到这一点?
【问题讨论】:
标签: asp.net asp.net-mvc security asp.net-identity
我有一个 Asp.net MVC 网站。当用户更改密码时,是否所有浏览器的登录都无效?我的意思是用户是否需要使用新密码登录所有浏览器?如果没有,有没有办法做到这一点?
【问题讨论】:
标签: asp.net asp.net-mvc security asp.net-identity
不是立即的,默认情况下,旧 cookie 在 asp.net 身份 2 中失效需要 30 分钟,asp.net 身份不会在每次请求时检查数据库,它有一个间隔,使用SecurityStamp要更改它,您可以在Startup.Auth.cs 中设置它,默认为 30 分钟,将validateInterval 设置为 0,这不是最有效的方法,因为在每次请求时都会访问数据库以检查 cookie 是否仍然有效,但如果你想立即看到效果,它会起作用,也可以看看this和this。
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.FromSeconds(0),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
【讨论】: