Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I best detect an ASP.NET expired session?

I need to detect when a session has expired in my Visuial Basic web application. This is what I'm using...

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

Note: CurrentSession.IsNew returns HttpContext.Current.Session.IsNewSession

This seems to work well for Internet Explorer, but seems to fail with Firefox.

like image 934
Zack Peterson Avatar asked Aug 06 '08 18:08

Zack Peterson


1 Answers

Try the following

If Session("whatever") IsNot Nothing Then
like image 57
Shawn Avatar answered Sep 20 '22 18:09

Shawn