我正在使用 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();
关于c# - 为什么安全印章不会注销用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36814022/