如何在会话超时或结束时注销用户
会话结束或过期时注销用户的最佳方法是什么?
感谢您的任何帮助。
Whats the best way to log out a user when a session ends or expires?
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这实际上取决于您正在寻找的所需功能。我假设您正在使用 FormsAuthentication。
您需要关注两件不同的事情:Session 和 FormsAuthentication cookie。除非我弄错了,否则这两个都有单独的超时。
如果您遇到的问题是会话超时但用户仍然经过身份验证,您可以尝试以下组合:
1:确保身份验证 cookie 具有与会话相同的超时值:
2:在您的Page_Load事件,检查会话是否超时:(
参见http://www.eggheadcafe.com/articles/20051228.asp 有关检测会话超时的信息)
如果您想要更愉快的用户体验,您可以使用 javascript 在 X 分钟后启动某种模式 UI 弹出窗口。此弹出窗口仅允许用户启动按钮单击,这将触发服务器上的 AJAX 回发,从而扩展其身份验证和会话 cookie,而无需重新加载页面。我以前从未实现过这个,但是看看, 这家伙做了一个ASP.NET AJAX 控件!
It really depends on the desired functionality you're looking for. I'm going to assume you're using FormsAuthentication.
There's two separate things you need to be concerned about: the Session and the FormsAuthentication cookie. Unless I'm mistaken, both of these have separate timeouts.
If the problem you're having is that the session is timed out but the user still is authenticated, you could try a combination of the following:
1: Making sure the authentication cookie has the same timeout value as the session:
2: In your Page_Load event, check if the session has timed out:
(See http://www.eggheadcafe.com/articles/20051228.asp for information on detecting a session timeout)
If you want a more pleasant user experience, you could use javascript to initiate some sort of a modal UI popup after X minutes. This popup would simply allow a user to initiate a button-click which would trigger an AJAX postback on the server, thus extending their authentication and session cookie without them having to reload the page. I've never implemented this before but look, this guy made an ASP.NET AJAX control !
如果您使用 .net 会员提供程序,只需在 web.config 中设置超时设置
http://msdn.microsoft.com/en-我们/库/h6bb9cz9(v=VS.100).aspx
If you are using the .net Membership Provider, just set the Timeout-setting in the web.config
http://msdn.microsoft.com/en-us/library/h6bb9cz9(v=VS.100).aspx