ASP.net Identity 2.0 Sign-out another user

后端 未结 2 1365
我寻月下人不归
我寻月下人不归 2020-12-01 18:13

I\'m using asp.net MVC and ASP.net Identity 2.0.

On my website Admin has option to ban user, and I would like when user is banned that he is automatically signed-out

相关标签:
2条回答
  • 2020-12-01 18:43

    You'll need to configure cookie invalidation in Auth.Config.cs:

    public void ConfigureAuth(IAppBuilder app)
    {
        // important to register UserManager creation delegate. Won't work without it
        app.CreatePerOwinContext(UserManager.Create);
    
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            Provider = new CookieAuthenticationProvider
            {
                OnValidateIdentity = SecurityStampValidator
                    .OnValidateIdentity<UserManager, ApplicationUser, int>(
                        validateInterval: TimeSpan.FromMinutes(10),
                        regenerateIdentityCallback: (manager, user) => user.GenerateUserIdentityAsync(manager))
            },
            // other configurations
        });
    
        // other stuff
    }
    

    and then update security stamp as Hao Kung says when users are banned.

    I've blogged about this recently

    0 讨论(0)
  • 2020-12-01 18:48

    If you use the securitystampvalidator feature, when a user is banned just call: UpdateSecurityStamp(userId) to cause any existing login cookies to be invalid the next time they are checked.

    More info about SecurityStamp?

    0 讨论(0)
提交回复
热议问题