简体   繁体   中英

Detect total time the user is logged-in asp.net

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_End event 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

You can capture exactly time from login to logout. If your users login, then user logout after complete their work.

You cannot capture extracly time from login to logout. If your users login once, and never comeback, or they clear their browser cached and login again ....

So, the best way to do that, You check user's access every 15 minutes. Last 15 minutes, your users don't do anything in your site, you assume that they logged out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM