本文介绍了如何在 ASP.NET Core Identity 中注销其他用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 ASP.NET Core Identity 中注销另一个用户(不是当前登录的用户).

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

我知道有一个 SignInManager 中的 code>SignOutAsync() 方法,但似乎没有覆盖接受用户作为参数.我正在寻找类似的东西:

I know there is a SignOutAsync() method in SignInManager, but there seems to be no override accepting user as argument. I'm looking for something like:

signInManager.SignOutAsync(user);

推荐答案

首先更新该用户的安全戳:

First update the security stamp of that user:

await userManager.UpdateSecurityStampAsync(user)

那么在 SecurityStampValidationInterval 到来之前,用户不会注意到这些变化.因此将其设置为 Zero 以立即注销:

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<User, Role>(identityOptions =>
{
   // enables immediate logout, after updating the user's stat.
   identityOptions.SecurityStampValidationInterval = TimeSpan.Zero;
}

更新:针对 ASP.NET Core Identity 2.x、3.x、5.x

Update: For ASP.NET Core Identity 2.x, 3.x, 5.x

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

这篇关于如何在 ASP.NET Core Identity 中注销其他用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 07:17