How do I forcefully propagate role changes to users with ASP.NET Identity 2.0.1?

后端 未结 1 1209
谎友^
谎友^ 2020-11-27 04:22

I\'ve read this and while it explains how role changes will eventually propagate to the user cookie after some time interval, I still don\'t understand how I force an im

相关标签:
1条回答
  • 2020-11-27 05:16

    If you want to enable immediate revocation of cookies, then every request must hit the database to validate the cookie. So the tradeoff between delay is with your database load. But you can always set the validationInterval to 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))
        }
    });
    
    0 讨论(0)
提交回复
热议问题