kumar
kumar

Reputation: 1127

how to kill the session when user closed the browser without logout

I am developing one aspnet application in that i am using Sessions. if user login into the application and click on logout here i am closing session.

suppose if the user doesn't click on the logout and he close the browser. how to kill the session when user closed the browser without logout

Upvotes: 3

Views: 6697

Answers (3)

blazzerbg
blazzerbg

Reputation: 36

Very difficult task:

  • use sessions with very smalll timeout /you will have expiration/

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

  • handle onunload event in window /can be bypassed/

Code sample:

window.onunload = function ()  
{    
    if((window.event.clientX<0) && (window.event.clientY<0)) {

       window.open("logoff.aspx");                  
    }    
}

Upvotes: 7

user348382
user348382

Reputation: 83

There is no way your application can know that the user has closed the browser. Session will be closed based on Session.Timeout

If the user does not refresh or request a page within the time-out period, the session ends.

Upvotes: 3

Johan Olsson
Johan Olsson

Reputation: 715

You can define what should happen when a Session expires in Global.asax.cs.

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

Edit: There is no way for the web server to know that you have closed a web browser.

Upvotes: 1

Related Questions