会话结束事件
我正在使用 ASP.net 3.5 C# 工作。我想做的是,当 Session_End 事件被调用时,我想更新数据库中当前用户已通过任何方式注销的登录用户状态(手动注销、会话超时等。它调用 Session_End 事件)。问题是我不愿意维护用户ID。我无法访问 Session 变量,因为会话已经过期,cookie 也对我不起作用。
请提出一个解决方案。
非常感谢
问候 维韦克
I am working in ASP.net 3.5 C#. What i am trying to do is when Session_End event gets called, I want to update the logged in User's status in database that the current User has logged out by any means (Logged out manually, Session time out etc. It calls Session_End Event). The problem is i am not bale to maintain the UserID. I can't access Session variable as session has already expired cookies also dint work for me.
Please suggest a solution.
Thanks a lot
Regards
Vivek
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将 UserID 推送到 ViewState,如果您有一个所有页面都继承自的 BasePage 或者如果您使用 MasterPage,那么将 UserID 推送到每个页面上的 viewstate 应该很容易。 Cookie 应该在会话生命周期结束后仍然有效。您是否为 cookie 设置了过期时间?
Try pushing the UserID to ViewState, if you have a BasePage from which all your pages inherit or if you use MasterPage then it should be quite easy to push the UserID to viewstate on each page. Cookies should be alive beyond session life. Are you setting Expiry time to your cookie?
您应该能够访问 Session_End 事件中的会话变量。 Session_End 事件完成后,会话中存储的所有数据都将被删除。但您应该小心,因为会话是为所有访问者创建的。如果您将 UserID 存储在会话中,那么如果有人查看了登录页面但未登录,则 Session_End 中的 UserID 可能为 null。不建议将会话超时设置为天,因为这些会话可能会填满所有服务器内存。
You should be able to access session variables in Session_End event. All data stored in a session are deleted after the Session_End event finished. But you should be careful, because sessions are created for all visitors. If you store UserID in a session then it can be null inside Session_End if someone viewed the login page, but did not log in. It is not recommended to set the session timeout to days, because these sessions may fill all server memory.