如何在ASP.NET Core身份中注销其他用户 [英] How to sign out other user in ASP.NET Core Identity

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

问题描述

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

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

我知道有一个 SignInManager中的c0> 方法,但是似乎没有覆盖将用户用作参数.我正在寻找类似的东西:

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

Update: For ASP.NET Core Identity 2.x

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆