asp.net-mvc-5 – aspnet身份避免同时登录同一帐户

我正在搜索,但我找不到这个问题的答案:aspnet身份提供了一种避免同时从同一帐户登录方法吗?

解决方法

身份没有内置的方式来跟踪同时登录,但您可以进行解决方法:每次用户登录时,在设置auth-cookie之前,通过等待userManager.UpdateSecurityStampAsync(user.Id)来更改用户的SecurityStamp;

并确保在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))
            }
        });

这样,每次用户登录时,所有其他会话都将失效,因为用户的SecurityStamp已更改.并且validateInterval值足够低,因此其他auth-cookies可以很快失效.

相关文章

ASP.NET与IIS是紧密联系的,由于IIS6.0与IIS7.0的工作方式的...
在之前的ASP.NET是如何在IIS下工作的这篇文章中介绍了ASP.NE...
这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...