0

I have one trouble that consist that when I'm using OWIN authentication and makes log in done and the browser or tab browser is closed, the session is still alive !!

There is a way to kill the session in the global asax file ?? Like session end method ??

When I'm make log off on my application I call an acction that contains the follow code:

[CustomValidateAntiForgeryToken]
        public ActionResult LogOff()
        {
            var authenticationManager = HttpContext.GetOwinContext().Authentication;
            authenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
            SqlConnectionManager.Instance = null;
            Session.Clear();
            Session.Abandon();
            Session.RemoveAll();
            return RedirectToAction("Index", "Account", new {area = string.Empty});
        }

But I would like to know how execute that code when the browser or tab browser is closed .. Thanks ...

1 Answers1

1

You can detect via javascript when the user closes the browser/tab and then call your code in the server. However, it doesn't work exactly as you might need it. See this post.

I suggest you to configure a proper timeout session for your application using the sessionState element in the web.config file. Then, you can handle the Session_End event in the global.asax file as you said for user data cleanup.

Community
  • 1
  • 1
Hernan Guzman
  • 1,235
  • 8
  • 14