首先更新该用户的安全标记:
await userManager.UpdateSecurityStampAsync(user)
然后,该用户将不会被注意到更改,直到到达SecurityStampValidationInterval
.因此,将其设置Zero
为立即注销:
services.AddIdentity(identityOptions => { // enables immediate logout, after updating the user's stat. identityOptions.SecurityStampValidationInterval = TimeSpan.Zero; }
更新:对于ASP.NET Core Identity 2.x
services.Configure(options => { // enables immediate logout, after updating the user's stat. options.ValidationInterval = TimeSpan.Zero; });