1

I am working on MVC web application in that i want to handle session if we are closing tab or closing browser user should get logout, if user set remember password then only it should get login for next login.

tereško
  • 58,060
  • 25
  • 98
  • 150
saylesh
  • 151
  • 1
  • 2
  • 12
  • possible duplicate of [Close/kill the session when the browser or tab is closed](http://stackoverflow.com/questions/1921941/close-kill-the-session-when-the-browser-or-tab-is-closed) – Nick Aug 01 '14 at 02:39

2 Answers2

1

The only stable way is to use Session_End in Global.asax.

protected void Session_End(object sender, EventArgs e)
{
    System.Diagnostics.Debug.WriteLine("Session_End");
    FormsAuthentication.Signout();
}

This is an event handler that gets called when the user session ends.

DanKodi
  • 3,550
  • 27
  • 26
  • Session_End is hardly stable... there are many situations that can result in Session_End not being called, for instance when the app pool is recycled. There is no guarantee it will get called. – Erik Funkenbusch Aug 01 '14 at 05:13
0

You would have to code a call in js to a controller action to ensure that the session is invalidated. Otherwise the session would just timeout naturally.

T McKeown
  • 12,971
  • 1
  • 25
  • 32