问题
I have this question you probably know the answer... My app is already functional and working fine. Whenever a user authenticates the app updates its model with the LastLoginDate, and when the user logs out the app updates its model with the LastLogOutDate. This works fine while the user keeps clicking on the logout link. However, if the user closes the windows the LastLogOut value never gets updated, and what happens is that Administrator sees users online that are not. The same thing happens when the user left the tab opened while working in something else and .NET loses session.
I'm not managing the session time nor any value like that. All I need to do is: if after a while there is no activity of the user, then Update LastLogOut value and set it to offline in its model, after that logout regularly. Same if user closes the window, but I think first case will work in both ways.
I hope you could give me a hand on this issue,
Thanks.
回答1:
You will need a trackable LastActivityTime
that gets updated on any GET/POST and also a (possibly configurable) timeout, say 20 minutes that when showing logged in users will compare the LastActivityTime
to DateTime.Now
and only return those that are within the timeout window.
You can also set the LastLogOutDate
to the LastActivityTime
plus the timeout whenever displaying to the admin.
来源:https://stackoverflow.com/questions/4973702/end-session-on-mvc