How to kill a session when the user closed the browser without logging out

I am developing one aspnet application in that I am using Session. if the user launches into the application and click "Logout" here, I close the session.

Suppose the user does not click on the exit and closes the browser. how to kill a session when the user closed the browser without logging out

+3
source share
3 answers

Very difficult task:

  • use sessions with a very small timeout / you will have an expiration /

  • use hidden script / iframe for ping server / you will have connection /

  • handle the onunload event in the window / can be bypassed /

Code example:

window.onunload = function () { if((window.event.clientX<0) && (window.event.clientY<0)) { window.open("logoff.aspx"); } } 
+7
source

It is impossible for your application to know that the user has closed the browser. Session will be closed based on Session.Timeout

If the user does not refresh or request the page during the wait period, the session ends.

+3
source

You can determine what should happen when the session expires in Global.asax.cs.

 protected void Session_End(Object sender, EventArgs e) { // Do stuff here... } 

Edit: The web server does not know that you have closed the web browser.

+1
source

All Articles