c# - 为什么安全印章不会注销用户?

标签 c# asp.net authentication asp.net-identity

我正在使用 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/

相关文章:

c# - 如何使用 C# 查找所有窗口?

c# - ASP.NET Gridview 复选框列 - Onclick 和 jquery

c# - 在 parse.com 中一次保存多个对象

jquery - 使用 jquery 代替 CURL 和身份验证

authentication - 如何为 JWT token 生命周期验证添加额外检查?

c# - 适用于 Android Xamarin/C# 的谷歌 API key 。 map 仅显示灰色网格

c# - 如何使用 C# 代码连接或登录 Odoo?在与 Odoo 连接后,如何从 C# 向 Odoo 数据库添加自定义字段?

c# - 在 WPF 中获取 TreeViewItem 的 Header 的高度

c# - Microsoft.ApplicationInsights 错误 : InstrumentationKey cannot be empty

c# - 表单例份验证 cookie 中的 ASP.NET MVC 用户数据与添加到 session