如何最好地检测ASP.NET过期会话?

12

我需要在我的Visual Basic网络应用程序中检测会话何时过期。这是我正在使用的内容...

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If CurrentSession.IsNew AndAlso (Not Page.Request.Headers("Cookie") Is Nothing) AndAlso (Page.Request.Headers("Cookie").IndexOf("ASP.NET_SessionId") >= 0) Then
        Response.Redirect("TimeOut.aspx")
    End If

    ...do something...

End Sub

注意: CurrentSession.IsNew 返回 HttpContext.Current.Session.IsNewSession

这似乎在 Internet Explorer 上运行良好,但在 Firefox 上似乎失败了。


你能在Global.asax中使用Session_End函数吗?http://articles.techrepublic.com.com/5100-10878_11-5771721.html - Michael Stum
我目前只在global.asax文件中使用Application_Error事件。也许我的会话处理也应该放在那里。但是,我如何在请求的页面加载时使用它呢? - Zack Peterson
1个回答

10

请尝试以下方法

If Session("whatever") IsNot Nothing Then

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接