How to sign out other user in ASP.NET Core Identity

后端 未结 2 1589
时光说笑
时光说笑 2020-12-08 01:34

How can i sign out another user (not the currently logged one) in ASP.NET Core Identity.

I know there is a SignOutAsync() method in SignInManager, but t

2条回答
  •  攒了一身酷
    2020-12-08 01:44

    First update the security stamp of that user:

    await userManager.UpdateSecurityStampAsync(user)
    

    Then that user won't be noticed the changes until the arrival of the SecurityStampValidationInterval. So set it to Zero for the immediate logout:

    services.AddIdentity(identityOptions =>
    {
       // enables immediate logout, after updating the user's stat.
       identityOptions.SecurityStampValidationInterval = TimeSpan.Zero;
    }
    

    Update: For ASP.NET Core Identity 2.x

    services.Configure(options =>
    {
        // enables immediate logout, after updating the user's stat.
        options.ValidationInterval = TimeSpan.Zero;   
    });
    

提交回复
热议问题