Can somebody tell me how can I close/kill the session when the user closes the browser? I am using stateserver mode for my asp.net web app. The onbeforeunload
method is not proper as it fires when user refreshes the page.
The user session should be terminated immediately if they close the browser tab or window.
You need to tell the server to kill a session variable. The only way to do that from javascript is to use Ajax to call some custom page, with for example as variable the session key you want to delete.
You can't. HTTP is a stateless protocol, so you can't tell when a user has closed their browser or they are simply sitting there with an open browser window doing nothing.
That's why sessions have a timeout - you can try and reduce the timeout in order to close inactive sessions faster, but this may cause legitimate users to have their session timeout early.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With