GlobaLevel
asked on
asp.net - user closes page need to reset session varaible...page_unload
When the user closes the page I need to reset the session variable....isnt page_unload used for this when hit the 'X" on the top right hand corner??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Implementing your requirement is a bit complicated. It needs a way the client (web browser / page) to inform your server side application that ALL your application pages have been closed. This can be done in several ways:
- Ajax request when the page closes: Whenever the user closes your page, it sends an ajax request to inform your app that the page has been closed and it will kill the session. But you will face a problem if there was several pages opened. The session will be killed if only one page is closed. You will need to find a way to fix this.
- Polling the server: I used this method in one of our web applications. It gives a good result for both, detecting who is online and using your app, and who went offline or closed you pages.
This approach consists of simply sending an ajax request from your page (client side) each interval (10 seconds maybe). The server receives this request and makes sure that the client has a page opened for your application. If the serve side app doesn't get a request for maybe 30 or more seconds, it can assume that all the pages to your application has been closed. The proble with this approach is that it will consider the page has been closed if the internet connection on the client side faced some trouble. This might cause some confusion for your user because the session expired although he didn't close the page.