End Session on MVC

元气小坏坏 提交于 2020-01-25 08:54:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!