获取会话在ASP.NET优雅到期 [英] Get Session to expire gracefully in ASP.NET

查看:86
本文介绍了获取会话在ASP.NET优雅到期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种方法来告诉ASP.NET杀当前会话和一个全新的开始了前/重定向到一个页面后。

I need a way to tell ASP.NET "Kill the current session and start over with a brand new one" before/after a redirect to a page.

下面就是我想要做的:

1)当会话在ASP.NET应用程序的主网页(或Global.asax中)已过期检测。

1) Detect when a session is expired in the master page (or Global.asax) of an ASP.NET application.

2)如果会话过期,将用户重定向到告诉他们,他们的会话过期的页面。在这个页面,它会等待5秒钟,然后将用户重定向到应用程序的主页面,或者他们可以点击一个链接,如果他们希望越早到那里。

2) If the session is expired, redirect the user to a page telling them that their session is expired. On this page, it will wait 5 seconds and then redirect the user to the main page of the application, or alternatively they can click a link to get there sooner if they wish.

3)用户到达主网页,并开始再次使用该应用程序。

3) User arrives at main page and begins to use the application again.

好了,到目前为止,我已经覆盖步骤1和2。我有一个使用IsNewSession属性和ASP.NET会话ID的cookie值检测会话过期的功能。如果它检测到它重定向会话过期,等待五秒钟,然后试图进入主网页。

Ok, so far I have steps 1 and 2 covered. I have a function that detects session expiry by using the IsNewSession property and the ASP.NET Session ID cookie value. if it detects an expired session it redirects, waits five seconds and then TRIES to go to the main page.

问题是,当它试图重定向,它会在母版页,以检测在会话过期的一部分,它返回true。我试过调用Session.Abandon(),Session.Clear(),即使设置会话为NULL,没有运气。

The problem is that when it tries to redirect, it gets to the part in the master page to detect an expired session and it returns true. I've tried calling Session.Abandon(), Session.Clear(), even setting the session to NULL, with no luck.

有人在那里已经有之前已经面临这个问题,所以我在社区的信心有一个很好的解决方案。先谢谢了。

Someone out there has had to have faced this problem before, so I'm confident in the community to have a good solution. Thanks in advance.

推荐答案

您所描述的问题,是因为asp.net被重用的SessionID,如果在的SessionID,当你调用放弃(在auth的cookie仍然存在),它只会重新使用它,你需要显式地创建一个新的SessionID据我所知是这样的:

The problem you are describing happens because asp.net is reusing the sessionid, if the sessionid still exists in the auth cookie when you call abandon() it will just reuse it, you need to explicitly create a new sessionid afaik something like:

 HttpCookie mycookie = new HttpCookie("ASP.NET_SessionId");
    mycookie.Expires = DateTime.Now.AddDays(-1);
    Response.Cookies.Add(mycookie);

这篇关于获取会话在ASP.NET优雅到期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆