Skip to main content
 首页 » 编程设计

c#之为什么安全戳不注销用户

2024年02月05日8wayfarer

我正在使用 ASP.NET 身份。当我阻止用户帐户时,它应该立即注销。 这是我的代码:

await UserManager.SetLockoutEnabledAsync(user.Id, true); 
await UserManager.SetLockoutEndDateAsync(user.Id,DateTime.Today.AddYears(10)); 
await UserManager.UpdateSecurityStampAsync(user.Id); 

在 Startup.Auth.cs 中:

app.UseCookieAuthentication(new CookieAuthenticationOptions 
            { 
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
                LoginPath = new PathString("/Account/Login"), 
                Provider = new CookieAuthenticationProvider 
                { 
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<AppUserManager, ApplicationUser>( 
                    validateInterval: TimeSpan.FromSeconds(0), 
                    regenerateIdentity: (manager, user) => manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie)) 
                } 
            }); 

但它不会注销用户。我做错了什么?

请您参考如下方法:

为什么不使用 AuthenticationManager.SignOut()?

var authenticationManager= HttpContext.GetOwinContext().Authentication; 
authenticationManager.SignOut();