如何使用ASP.NET Identity 2.0.1强制传播angular色更改给用户?

我已经阅读了这篇文章 ,并解释了angular色更改最终会在一段时间之后传播到用户cookie,但我仍然不明白如何强制立即更改用户angular色。

当我以pipe理员身份更改angular色时,是否真的必须签署该用户? 如果是这样 – 如何? 如果我使用AuthenticationManager.SignOut(); 那么我签下自己(pipe理员),而不是用户,他们的angular色,我想改变。

目前我使用await UserManager.UpdateSecurityStampAsync(user.Id); 生成一个新的安全印章,但它不起作用。 当我以另一个用户身份login另一个浏览器刷新一个页面时,他的声明(包括安全标记)不会改变。

如果您想立即吊销cookie,那么每个请求都必须打到数据库才能validationcookie。 所以延迟之间的折衷是与你的数据库负载。 但是你总是可以设置validationInterval为0。

  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)) } }); 

这里的问题是Web服务器caching了这些数据。 最终,caching将从数据库中自行刷新,但不是立即。 这就是为什么有一个延迟。

我认为,显而易见的事情是回收应用程序池。 现有的请求将继续旧的进程,当它们全部完成时将终止。 现在请求将进入不会caching数据的新进程,因此会在第一次访问时从数据库读取新数据。