关闭浏览器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分钟后注销用户,而且还要关闭浏览器。

解决方法

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