ASP.NET会话超时太早

ASP.NET会话超时太早

问题描述:

我想,当身份验证的用户创建一个新的会话创建日志,但由于某些原因,我碰到的奇怪的行为。为了测试设置我的会话超时2分钟在web.config中:

I'm trying to create a log when an authenticated user creates a new session, but for some reason I've run into odd behavior. For testing I set my Session timeout to 2 minutes in web.config:

<sessionState cookieName="AppName_SessionId" timeout="2" />   

而在Global.asax.vb我有以下的code登录:

And in Global.asax.vb I have the following code to log:

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)

   If My.User.IsAuthenticated = True Then
      Log.Create()
   End If
End Sub

一切工作正常后,我登录,关闭浏览器,然后重新打开。它只记录一次,而我访问过的网页,而我在会议上我。问题是,当我停下来,让会议为止(2分钟测试),然后再试一次。它记录新的会话,这是我期望的行为,但随后在session_start上每个页面视图下焙烧。我证实了这一点在不同的浏览器。

Everything works correctly after I login, close the browser and reopen it. It only logs once while I visit pages while I'm in the session. The problem is when I stop and let the session expire (2 minutes for testing) and try again. It logs the new session, which is the behavior I expect, but then the Session_Start is fired on every page view thereafter. I confirmed this on different browsers.

看来,一旦会话已过期,浏览器仍然是开放的,它无法维持会话。

It appears that once the session has expired and the browser is still open, that it cannot maintain the session.

我的修复是什么添加到会话:

My fix was to add something to the Session:

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) 

   If My.User.IsAuthenticated = True Then 
      Log.Create() 
      Session("SessionLogged") = True
   End If 

End Sub