C# 仅在浏览器窗口的生命周期内进行Web安全登录
我正在使用ASP.NET中的SimpleMemberships来处理用户的登录和注销,我想知道是否有人知道如何设置它,以便他们的登录会话在浏览器关闭时过期 我将persistCookie设置为false,但即使在关闭浏览器后,它仍会使它们保持登录状态 编辑:C# 仅在浏览器窗口的生命周期内进行Web安全登录,c#,asp.net,asp.net-mvc-4,simplemembership,C#,Asp.net,Asp.net Mvc 4,Simplemembership,我正在使用ASP.NET中的SimpleMemberships来处理用户的登录和注销,我想知道是否有人知道如何设置它,以便他们的登录会话在浏览器关闭时过期 我将persistCookie设置为false,但即使在关闭浏览器后,它仍会使它们保持登录状态 编辑: [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public ActionResult Login(LoginMo
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, false))
{
return RedirectToLocal(returnUrl);
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
当浏览器即将关闭时,您可以将页面指向注销url,请尝试以下JavaScript
window.onbeforeunload =function(){
location.href = 'signOutUrl';
}
但问题是你不能保证用户会关闭浏览器。也许他可以断开互联网。而且,由于此客户端JavaScript解决方案用户可以轻松更改此代码。如果cookie不像您的情况那样是持久的,它将存储在当前浏览器实例的内存中,当您关闭它时,cookie将丢失。确保已关闭所有浏览器窗口和选项卡(如果有的话)。是否关闭所有浏览器窗口?