我在ASP.NET中使用SimpleMemberships来处理登录和退出的用户,我想知道是否有人知道如何设置它以便他们的登录会话在浏览器关闭时到期。
我将persistCookie设置为false,但即使关闭浏览器后它仍会保持登录状态。
编辑:
[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);
}
答案 0 :(得分:2)
如果cookie在您的情况下不是持久性的,它将存储在当前浏览器实例的内存中,当您关闭它时,cookie将丢失。如果你有任何浏览器窗口和标签,请确保已关闭所有浏览器窗口和标签。
答案 1 :(得分:1)
您可以在浏览器关闭时将页面定向到注销网址,试试此JavaScript
window.onbeforeunload =function(){
location.href = 'signOutUrl';
}
但问题是您无法保证用户将关闭浏览器。可能是他可以断开互联网。此外,由于此客户端JavaScript解决方案用户可以轻松更改此代码。