ASP.NET会话超时太早 [英] ASP.NET Session Timeouts too early

查看:92
本文介绍了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 

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

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