会话在20分钟后到期:是否空闲

时间:2010-10-26 13:36:57

标签: asp.net iis-6 session-state asp.net-4.0 session-timeout

我遇到一些问题,用户在浏览申请表时会丢失会话数据。看起来他们正在通过申请表部分失去会话状态。 (ASP.NET 4.0 WebForms项目,IIS 6.0)

会话存储在状态服务器的进程外,因此它不是配置更改,appdomain回收等AFAIK。

<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" timeout="20" />

我正在使用表单身份验证,滑动过期工作正常,您可以从下面的日志中看到 - 您可以看到故障单过期时间正确并且被扩展为已显示。

<authentication mode="Forms">
   <forms loginUrl="~/Login.aspx" />
</authentication>

我启用了一些自定义日志记录来尝试跟踪此问题。在Session_Start global.asax的每个CType(ctx.User.Identity, FormsIdentity).Ticket.Expiration.ToString火上我记录了一些东西,每次有人加载申请表时我都会记录一些内容,或者当他们浏览应用程序时单击“下一步”以在各个部分之间移动(在MultiView中)形式。

以下是人们失去会话状态的两个例子。日志以日志条目的日期/时间开始,然后是一些措辞。括号中的第二个日期/时间(在措辞之后)是从Dim m As Member = StateManager.CurrentMember

派生的FormsAuthentication cookie的到期日期/时间

日志记录还会记录用户的IP地址和会话ID。我在删除它们之前删除了这些,我可以确认所有日志条目的IP地址和会话ID是相同的。

示例1:

**[26/10/2010 13:07]    Session started []**
[26/10/2010 13:11]  Application form first Page_Load [26/10/2010 13:31:19]
[26/10/2010 13:13]  App form next clicked, current index is 1 (vwSection1) [26/10/2010 13:31:19]
[26/10/2010 13:14]  App form next clicked, current index is 2 (vwSection2) [26/10/2010 13:31:19]
[26/10/2010 13:15]  App form next clicked, current index is 3 (vwSection3) [26/10/2010 13:31:19]
[26/10/2010 13:20]  App form next clicked, current index is 5 (vwSection4) [26/10/2010 13:31:19]
[26/10/2010 13:20]  App form next clicked, current index is 6 (vwSection5) [26/10/2010 13:31:19]
[26/10/2010 13:20]  App form next clicked, current index is 7 (vwMonitoring) [26/10/2010 13:31:19]
[26/10/2010 13:21]  App form next clicked, current index is 8 (vwInformation) [26/10/2010 13:31:19]
[26/10/2010 13:22]  Application form first Page_Load [26/10/2010 13:41:22]
[26/10/2010 13:25]  App form next clicked, current index is 1 (vwSection1) [26/10/2010 13:41:22]
[26/10/2010 13:26]  App form next clicked, current index is 2 (vwSection2) [26/10/2010 13:41:22]
[26/10/2010 13:26]  App form next clicked, current index is 3 (vwSection3) [26/10/2010 13:41:22]
[26/10/2010 13:28]  App form next clicked, current index is 5 (vwSection4) [26/10/2010 13:41:22]
[26/10/2010 13:28]  App form next clicked, current index is 6 (vwSection5) [26/10/2010 13:41:22]
[26/10/2010 13:28]  App form next clicked, current index is 7 (vwMonitoring) [26/10/2010 13:41:22]
[26/10/2010 13:28]  App form next clicked, current index is 8 (vwInformation) [26/10/2010 13:41:22]
**[26/10/2010 13:28]    Session started [26/10/2010 13:41:22]**
[26/10/2010 13:31]  Application form first Page_Load [26/10/2010 13:51:24]
[26/10/2010 13:31]  App form next clicked, current index is 1 (vwSection1) [26/10/2010 13:51:24]
[26/10/2010 13:32]  App form next clicked, current index is 2 (vwSection2) [26/10/2010 13:51:24]
[26/10/2010 13:32]  App form next clicked, current index is 3 (vwSection3) [26/10/2010 13:51:24]
[26/10/2010 13:32]  App form next clicked, current index is 5 (vwSection4) [26/10/2010 13:51:24]
[26/10/2010 13:32]  App form next clicked, current index is 6 (vwSection5) [26/10/2010 13:51:24]
[26/10/2010 13:32]  App form next clicked, current index is 7 (vwMonitoring) [26/10/2010 13:51:24]
[26/10/2010 13:32]  App form next clicked, current index is 8 (vwInformation) [26/10/2010 13:51:24]

示例2:

**[24/10/2010 17:44]    Session started []**
[24/10/2010 17:50]  Application form first Page_Load [24/10/2010 18:10:13]
[24/10/2010 18:00]  App form next clicked, current index is 1 (vwSection1) [24/10/2010 18:20:40]
**[24/10/2010 18:07]    Session started [24/10/2010 18:20:40]**
[24/10/2010 18:08]  App form next clicked, current index is 2 (vwSection2) [24/10/2010 18:20:40]
[24/10/2010 18:10]  App form next clicked, current index is 2 (vwSection2) [24/10/2010 18:20:40]
[24/10/2010 18:10]  App form next clicked, current index is 1 (vwSection1) [24/10/2010 18:30:42]
[24/10/2010 18:10]  App form next clicked, current index is 1 (vwSection1) [24/10/2010 18:30:52]
[24/10/2010 18:10]  App form next clicked, current index is 1 (vwSection1) [24/10/2010 18:30:58]
[24/10/2010 18:12]  Application form first Page_Load [24/10/2010 18:31:35]
[24/10/2010 18:12]  App form next clicked, current index is 1 (vwSection1) [24/10/2010 18:31:35]
[24/10/2010 18:13]  App form next clicked, current index is 2 (vwSection2) [24/10/2010 18:31:35]
[24/10/2010 18:13]  App form next clicked, current index is 2 (vwSection2) [24/10/2010 18:31:35]
[24/10/2010 18:16]  App form next clicked, current index is 3 (vwSection3) [24/10/2010 18:31:35]
[24/10/2010 18:16]  App form next clicked, current index is 5 (vwSection4) [24/10/2010 18:31:35]
[24/10/2010 18:17]  App form next clicked, current index is 6 (vwSection5) [24/10/2010 18:31:35]
[24/10/2010 18:18]  App form next clicked, current index is 7 (vwMonitoring) [24/10/2010 18:31:35]
[24/10/2010 18:18]  App form next clicked, current index is 8 (vwInformation) [24/10/2010 18:31:35]

您可以在第一个示例中看到会话最初是在13:07开始,但也是在13:28开始。

您可以在第二个示例中看到该会话最初于17:44开始,并在18:07重新启动。

据我所知,这些时间是会议开始后20分钟。但会议空闲。由于日志的其余部分,您可以看到它没有空闲。单击应用程序表单中的“下一步”可以获得会话状态

之外的对象
HttpContext.Current.Session("CurrentMember")

然后获取/设置“m”的属性。

所以,对我而言,即使用户没有空闲并访问他们的会话变量,他们仍然会在他们开始后20分钟正在丢失会话。请注意,在我的基页(所有页面继承,基页继承System.Web.UI.Page)中,我现在已开始将当前毫秒写入会话状态,因此我不断写入会话。

用户正在丢失其会话状态,因为StateManager.CurrentMember(只是{{1}})返回null。当我尝试将它附加到实体框架数据上下文时,这会给出一个未处理的异常 - 因此用户可以看到我的通用错误处理页面。

任何想法都赞赏。

3 个答案:

答案 0 :(得分:1)

您提到您正在使用FormsAuthentication。您是否将滑动过期属性设置为true?

http://msdn.microsoft.com/en-us/library/1d3t3c61(v=VS.100).aspx

答案 1 :(得分:0)

我唯一一次看到这样的事情发生的时候是我在代码中引用了localhost。

虽然你说它在某个地方的某个其他服务器上,但我认为刷新AppPool会松开对Session信息的引用,从而创建另一个。 尝试此操作的一种方法是转到IIS并进行配置,更新错误会导致池的刷新,导致可能永远不会刷新的情况,然后您可能会找到所需的内容。试试看,让我知道。

答案 2 :(得分:0)

默认IIS应用程序池超时为20分钟。这可能有所帮助:MSDN