首页 > 解决方案 > 关闭浏览器 ASP.NET MVC 后如何注销用户

问题描述

PasswordSignInAsync我使用类似的功能登录

var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.Remember, shouldLockout: false);

并且字段model.Remember (isPersistent)是错误的。

在我的 Startup 课程中,我有一些代码,例如

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

我想要实现的不仅是在 30 分钟后注销用户,还要在关闭浏览器后注销用户。

标签: c#asp.netasp.net-mvcauthentication

解决方案


window.unload从客户端尝试清除cookie吗?也许这可以解决您的问题。


推荐阅读