gpt4 book ai didi

c# - 如何注销 ASP.NET Core Identity 中的其他用户

转载 作者:太空狗 更新时间:2023-10-29 17:38:57 29 4
gpt4 key购买 nike

如何在 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com