如何注销用户时,会话超时或结束

编程入门 行业动态 更新时间:2024-10-25 00:31:50
本文介绍了如何注销用户时,会话超时或结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

请告诉我注销用户在会话结束或过期的最佳方法?

Whats the best way to log out a user when a session ends or expires?

感谢您的帮助。

推荐答案

这真的取决于你在寻找所需的功能。我会假设你正在使用FormsAuthentication。

It really depends on the desired functionality you're looking for. I'm going to assume you're using FormsAuthentication.

有是你需要关心两回事:在会话和 FormsAuthentication 的cookie。除非我错了,这两个具有独立的超时。

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:确保身份验证Cookie具有相同的超时值作为会话:

1: Making sure the authentication cookie has the same timeout value as the session:

<authentication mode="Forms"><forms ... timeout="20" ... ><authentication> <sessionState ... timeout="20" ... />

2:在你的Page_Load事件中,检查是否会话超时:

2: In your Page_Load event, check if the session has timed out:

if (context.Session != null && Context.Session.IsNewSession == true && Page.Request.Headers["Cookie"] != null && Page.Request.Headers["Cookie"].IndexOf("ASP.NET_SessionId") >= 0) { // session has timed out, log out the user if (Page.Request.IsAuthenticated) { FormsAuthentication.SignOut(); } // redirect to timeout page Page.Response.Redirect("/Timeout.aspx"); }

(见www.eggheadcafe/articles/20051228.asp对检测会话超时信息)

如果你想要一个更愉快的用户体验,您可以使用JavaScript X分钟后启动某种模态UI弹出窗口。该弹出只会允许用户启动一个按钮,点击它会触发服务器上的AJAX回传,从而延长他们无需重新加载页面的认证和会话cookie。我从来没有实现这之前,但看起来,这个家伙做了ASP.NET AJAX控制!

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 !

更多推荐

如何注销用户时,会话超时或结束

本文发布于:2023-11-12 01:44:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580158.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:结束   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!