结束 MVC 上的会话
我有这个问题,您可能知道答案...我的应用程序已经可以正常运行。每当用户对应用程序进行身份验证时,应用程序都会使用 LastLoginDate 更新其模型,而当用户注销时,应用程序会使用 LastLogOutDate 更新其模型。当用户不断单击注销链接时,这可以正常工作。但是,如果用户关闭窗口,LastLogOut 值永远不会更新,并且管理员会看到未在线的用户。当用户在处理其他事情时保持选项卡打开并且 .NET 丢失会话时,也会发生同样的情况。
我不管理会话时间或任何类似的值。我需要做的就是:如果一段时间后用户没有任何活动,则更新 LastLogOut 值并将其在模型中设置为离线,之后定期注销。如果用户关闭窗口也是如此,但我认为第一种情况在两种情况下都有效。
希望您能帮我解决这个问题,
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要一个可跟踪的
LastActivityTime
,它会在任何 GET/POST 上更新,并且还需要一个(可能可配置的)超时,例如 20 分钟,当显示登录用户时,它将比较LastActivityTime
到DateTime.Now
并且只返回超时窗口内的那些。您还可以将
LastLogOutDate
设置为LastActivityTime
加上向管理员显示时的超时时间。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 theLastActivityTime
toDateTime.Now
and only return those that are within the timeout window.You can also set the
LastLogOutDate
to theLastActivityTime
plus the timeout whenever displaying to the admin.