Logoff User when browser tab page is closed, ASP.NET MVC

后端 未结 5 427
攒了一身酷
攒了一身酷 2021-02-06 02:29

In one of the ASP.NET MVC apps we would like to logoff the user automatically if he closes the browser tab in which the app is opened.

We are using the following code wh

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-06 02:48

    Actually there is no way we can LogOff the user when the user closes the browser tab. The only way for this is to check if the the user is authenticated when we call the LogOn method in the Controller.

    This code is an example of how I do it in ASP.Net MVC 3.

    public ActionResult LogOn()
            {
                if (Request.IsAuthenticated)
                {
                    FormsAuthentication.SignOut();
                    return RedirectToAction("Index","ProductManager");  
                }
               return View();          
            }
    

提交回复
热议问题