I have asp.net web site in which user can login and also do logout
Now i need to capture the total time duration for which user was logged-in to the site.
So to do this i need to know two things
1. Login time
2. Logout time
At the time of login i can get the first thing which is “Login time”, thats fairly easy
Now the second thing is more complicated. How do i update the Logout time? I know i can update it on the logout button but what if user directly close the browser?
I have setup the global.asax file but i dont think “Session_End” event will fire on closing the browser.
I have seen some of the website in which where you close the browser window it shows on dialog saying something like “press Ok to stay on the page OR press “Cancel” to stay on the current page”. I am thinking i can use the UpdatePanel’s PageMethods to do my task here. Is this possible? If yes then how?
Do you guys have any other idea to find out the total logged-in time for the user?
Thank you.
I haven’t tried this but you can use the Window Close Event of the browser and make an ASP.net AJAX call to the server using AJAX page methods to end the Session, which you can catch in the
Session_Endevent in global.asax file of your application.There are some problems with this approach as the Window close event is not 100% guaranteed to fire, because the user can simple end the process using task manager.
Check https://stackoverflow.com/q/1824486/507184 for a jquery based solution for detecting browser close event