1

我在 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);
        }
4

2 回答 2

2

If the cookie is not persistent as in your case, it is stored in the memory of the current browser instance and when you close it, the cookie will be lost. Make sure though that you have closed all browser windows and tabs if you had any.

于 2013-08-15T04:13:17.393 回答
1

当浏览器要关闭时,您可以将页面定向到注销 url,试试这个 JavaScript

window.onbeforeunload =function(){
 location.href = 'signOutUrl'; 
}

但问题是你不能保证用户会关闭浏览器。也许他可以断开互联网。而且由于这个客户端 JavaScript 解决方案用户可以轻松更改此代码。

于 2013-08-15T03:45:43.697 回答