Click here to Skip to main content
14,973,198 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am inserting user details when user login in my website.

At the time of user logout then i have to update logout status .

if user logout properly i can catch the status as logout but if user close the browser without click logout button then how can i catch the user has logout??

Please help me how to solve this problem
Updated 12-May-20 23:49pm

You can't, not reliably.
There is an javascript event you can catch (onunload) but it works in IE, but not for FireFox, and there is onbeforeunload which works in Firefox, but there is no simple "do this" which works, guaranteed, for all browsers. To add to that, what if the user unplugs the router, or has a power cut, or goes into a tunnel, or runs out of battery power? What happens if your app crashes before he logs out?

Use the session timeout to log out your user if he hasn't before, and allow your system to work gracefully if a user tries to log in without a matching log out.
You can capture browser close button click event using JavaScript and you can call the Logout method in that.
Something like this,
window.onbeforeunload = function() {
// make an Ajax call to server side Logout method.
// In the Logout method you can get/set the success status

You can make an Ajax call to a code behind method. Please check the following link,[^]

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