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

Question

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.

Answer

Try the following

If Session("whatever") IsNot Nothing Then
< br > via < a class="StackLink" href=" http://stackoverflow.com/questions/3831/" >How do I best detect an ASP.NET expired session?< /a>
Share on Google Plus

About Cinema Guy

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment