Thi*_*dio 7 asp.net-mvc-5 asp.net-identity asp.net-mvc-5.1 asp.net-identity-2
我正在搜索,但我找不到这个问题的一个答案:aspnet身份提供了一种避免同时从同一帐户登录的方法吗?
tra*_*max 10
标识不具有一个内置的方式来跟踪同时登录,但你可以做一个变通办法:每次用户登录,在,前设置身份验证cookie的,更改用户SecurityStamp通过await userManager.UpdateSecurityStampAsync(user.Id);
并确保你有这个部分Startup.Auth.cs:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
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(5),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
Run Code Online (Sandbox Code Playgroud)
这样,每次用户登录时,所有其他会话都将失效,因为用户的SecurityStamp已更改.并且validateInterval足够低,因此其他auth-cookies可以很快失效.
| 归档时间: |
|
| 查看次数: |
3149 次 |
| 最近记录: |