Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to kill user session variable if any action is occured.
Either closed by close button,
Closed by alt+f4, closed by task manager or task bar.
Posted

1 solution

There is no way to guarantee what you want so you may want to rethink what you are trying to do.

However, you can use the onunload event, http://www.w3schools.com/jsref/event_onunload.asp[^], to then call a webservice that will do what you want.

jQuery's .ajax() makes it easy to call a webservice. http://api.jquery.com/jQuery.ajax/[^]
 
Share this answer
 
Comments
Mayank_1986 17-Apr-15 0:36am    
Thanks Ryan,
Actually i have an application for client support. My problem is that once a user logged-in into application, session has been maintained to server for 1 hrs(set as default timeout). Now as soon as user closed the browser(tab as well) and try to login, the session has already found for that user but have different session id.
The application will only permit to login to that user if its session is not available on server, but somehow it was found on server and expires only after 1hrs as we have set.
So i need to kill session variable if user forcefully closed browser by using any method (eg. by close button, by Alt+f4 key, by task manager or by task bar).
As you have mentioned to use onunload, it will works only if user closed browser by close button.
ZurdoDev 17-Apr-15 8:19am    
It works if the user closes the window. Nothing will catch closing it in Task Manager.

The other option you have is to use setTimeout in JS and every minute call a webservice. Then you can have a windows service running that clears out sessions that have not "pinged" within the last few minutes.

Sounds like your best option is to train users to click Logout.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900