ASP.NET会话超时重定向不起作用
我遇到以下问题 我在Global.asax中添加了此代码ASP.NET会话超时重定向不起作用,asp.net,vb.net,Asp.net,Vb.net,我遇到以下问题 我在Global.asax中添加了此代码 Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when a new session is started Session("Startdatetime") = DateTime.Now End Sub 并在会话结束时发送电子邮件通知,告诉我会话结束正在启动 sessionValue是SessionSta
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a new session is started
Session("Startdatetime") = DateTime.Now
End Sub
并在会话结束时发送电子邮件通知,告诉我会话结束正在启动
sessionValue是SessionStartdatetime
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
emailCenter.sendNotification(sessionvalue, "Session_End", "myemail@gmail.com")
End Sub
然后在Default.aspx/page加载中,如果会话过期,则调用此方法返回true
If IsSessionExpired() Then
Response.Redirect("sessionTimeout.html")
End If
Public Function IsSessionExpired() As Boolean
'??? not working
If HttpContext.Current.Session IsNot Nothing Then
If (HttpContext.Current.Session.IsNewSession) Then
Dim CookieHeaders As String = HttpContext.Current.Request.Headers("Cookie")
If IsNothing(CookieHeaders) And (CookieHeaders.IndexOf("ASP.NET_SessionId") >= 0) Then
' IsNewSession is true and session cookie exists,
' so, ASP.NET session is expired
Return True
End If
End If
End If
' Session is not expired and function will return False,
' it could be new session, or existing active session
Return False
End Function
我已经在web.config中设置了它,将超时设置为1分钟
<sessionState mode="InProc" cookieless="UseCookies" timeout="1" />
会话结束正在触发,但IsSessionExpired永远不会返回true
我没有使用母版页进行此测试
发生了什么事?如果没有CookieHeaders,那么它应该是如果没有CookieHeaders?是的,我找到了。应该是:如果没有,那么是:如果没有CookieHeaders和CookieHeaders.IndexOfASP.NET\u SessionId>=0