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

标签 c# asp.net-core asp.net-core-mvc asp.net-core-identity

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

相关文章:

c# - dotnet 核心方法 'ValidateOptions' ... 没有实现

c# - 如何在 ASP.NET Core MVC 中使用依赖注入(inject)设计存储库模式?

node.js - ASP.NET Core MVC 项目中的 node_modules 文件夹

asp.net - 使用 ASP.NET MVC 6 在 Web.config 中设置 IIS 设置

c# - 带有数据网格和 TabControl 的 WPF MVVM Master 详细信息 View

c# - Collat​​z 序列 - 减去错误

c# - 为什么 Polly 不在我的单元测试中重试异常?

c# - 在 .net 核心中配置依赖注入(inject)

asp.net-core - ASP.NET Core 2.x OnConfiguring 从 appsettings.json 获取连接字符串

c# - System.IO.File.Delete 抛出算术运算导致溢出