如何在 ASP.NET Core Identity 中注销另一个用户(不是当前登录的用户)。
我知道有一个 SignOutAsync()
SignInManager
中的方法,但似乎没有覆盖接受用户作为参数。我正在寻找类似的东西:
signInManager.SignOutAsync(user);
最佳答案
首先更新该用户的安全标记:
await userManager.UpdateSecurityStampAsync(user)
然后在 SecurityStampValidationInterval
到来之前,该用户不会注意到更改。因此将它设置为 Zero
以立即注销:
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
services.Configure<SecurityStampValidatorOptions>(options =>
{
// enables immediate logout, after updating the user's stat.
options.ValidationInterval = TimeSpan.Zero;
});
关于c# - 如何注销 ASP.NET Core Identity 中的其他用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41629691/