ASP.NET会话超时重定向不起作用

时间:2015-01-05 04:19:53

标签: 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

并在Session_end中发送电子邮件通知,告诉我Session_end正在触发    sessionValue是Session(" Startdatetime")

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" />

session_end正在触发,但IsSessionExpired()永远不会返回true !!

我没有使用Master Page进行此测试。

发生了什么事?

0 个答案:

没有答案
相关问题