Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to handle Invalid Session State on callback

How to handle Invalid Session State on callback

Scheduled Pinned Locked Moved ASP.NET
helpsysadmintestingbeta-testingtutorial
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    David Mujica
    wrote on last edited by
    #1

    I have a page that performs a callback and I'm trying to handle the situation where the session has expired, but the callback is still being invoked. I'm using the following code in my Global.asax

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)

        Dim httpApp As HttpApplication = Context.ApplicationInstance
        Dim httpEx As HttpException = httpApp.Server.GetLastError
    
        If (httpEx IsNot Nothing) Then
            If (httpEx.WebEventCode = System.Web.Management.WebEventCodes.AuditInvalidViewStateFailure Or \_
                       httpEx.WebEventCode = System.Web.Management.WebEventCodes.InvalidViewState Or \_
                       httpEx.WebEventCode = System.Web.Management.WebEventCodes.InvalidViewStateMac Or \_
                       httpEx.WebEventCode = System.Web.Management.WebEventCodes.RuntimeErrorViewStateFailure) Then
                HttpContext.Current.ClearError()
    
                Response.Redirect("~/MyErrorPage.aspx", True)
    
            End If
        End If
    
    End Sub
    

    The problem is that it is not redirecting to my error page. I'm testing this out on an IIS7 server and I force the error by stopping, then restarting the application pool on the server in between requests. Maybe I'm performing the wrong type of test. Shouldn't this re-direction work? Am I performing the correct type of test ? Ugh. :confused:

    Kornfeld Eliyahu PeterK 1 Reply Last reply
    0
    • D David Mujica

      I have a page that performs a callback and I'm trying to handle the situation where the session has expired, but the callback is still being invoked. I'm using the following code in my Global.asax

      Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)

          Dim httpApp As HttpApplication = Context.ApplicationInstance
          Dim httpEx As HttpException = httpApp.Server.GetLastError
      
          If (httpEx IsNot Nothing) Then
              If (httpEx.WebEventCode = System.Web.Management.WebEventCodes.AuditInvalidViewStateFailure Or \_
                         httpEx.WebEventCode = System.Web.Management.WebEventCodes.InvalidViewState Or \_
                         httpEx.WebEventCode = System.Web.Management.WebEventCodes.InvalidViewStateMac Or \_
                         httpEx.WebEventCode = System.Web.Management.WebEventCodes.RuntimeErrorViewStateFailure) Then
                  HttpContext.Current.ClearError()
      
                  Response.Redirect("~/MyErrorPage.aspx", True)
      
              End If
          End If
      
      End Sub
      

      The problem is that it is not redirecting to my error page. I'm testing this out on an IIS7 server and I force the error by stopping, then restarting the application pool on the server in between requests. Maybe I'm performing the wrong type of test. Shouldn't this re-direction work? Am I performing the correct type of test ? Ugh. :confused:

      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu Peter
      wrote on last edited by
      #2

      The fact that your session is went done will not stop the web page to work perfectly correct! ViewState and all the related info was posted to the client (in hidden fields) and will be reused on the next post-back. The only problem with session down is authentication and data you stored on the session (ASP.NET engine do not store nothing on the session by default)... More! You are using down-casting here which can be very dangerous...Who told you GetLastError will return an HttpException! Maybe it's a SystemException or a plain Exception?! Also, if you read explanations of the error codes you use, you will see that none of them is connected to session end - http://msdn.microsoft.com/en-us/library/system.web.management.webeventcodes(v=vs.110).aspx[^] If you want to catch session end - and maybe set a flag for later use - see for Globla.asax...

      I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

      "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

      D 1 Reply Last reply
      0
      • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

        The fact that your session is went done will not stop the web page to work perfectly correct! ViewState and all the related info was posted to the client (in hidden fields) and will be reused on the next post-back. The only problem with session down is authentication and data you stored on the session (ASP.NET engine do not store nothing on the session by default)... More! You are using down-casting here which can be very dangerous...Who told you GetLastError will return an HttpException! Maybe it's a SystemException or a plain Exception?! Also, if you read explanations of the error codes you use, you will see that none of them is connected to session end - http://msdn.microsoft.com/en-us/library/system.web.management.webeventcodes(v=vs.110).aspx[^] If you want to catch session end - and maybe set a flag for later use - see for Globla.asax...

        I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

        D Offline
        D Offline
        David Mujica
        wrote on last edited by
        #3

        Hmmm. It seems thatI misunderstood the example code that I took off the web. I will do some more research and re-attempt a solution. Question: What is the best way to perform a session timeout situation? Is it possible in the VS2010 IDE ? I've been publishing my App to a Sandbox IIS7 server and I've set the timeout to 1 minute, but this is cumbersome and difficult to debug. Thanks for your help.

        Kornfeld Eliyahu PeterK 1 Reply Last reply
        0
        • D David Mujica

          Hmmm. It seems thatI misunderstood the example code that I took off the web. I will do some more research and re-attempt a solution. Question: What is the best way to perform a session timeout situation? Is it possible in the VS2010 IDE ? I've been publishing my App to a Sandbox IIS7 server and I've set the timeout to 1 minute, but this is cumbersome and difficult to debug. Thanks for your help.

          Kornfeld Eliyahu PeterK Offline
          Kornfeld Eliyahu PeterK Offline
          Kornfeld Eliyahu Peter
          wrote on last edited by
          #4

          You can add a button (in debug mode) that will call Session.Abandon[^] for you...

          I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

          "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

          D 1 Reply Last reply
          0
          • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

            You can add a button (in debug mode) that will call Session.Abandon[^] for you...

            I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

            D Offline
            D Offline
            David Mujica
            wrote on last edited by
            #5

            session.Abandon() is exactly what I needed. Test is perfect. I will start a new thread for my next issue. "Response.Redirect" is not allowed in Callback. Thanks for all your help.

            Kornfeld Eliyahu PeterK 1 Reply Last reply
            0
            • D David Mujica

              session.Abandon() is exactly what I needed. Test is perfect. I will start a new thread for my next issue. "Response.Redirect" is not allowed in Callback. Thanks for all your help.

              Kornfeld Eliyahu PeterK Offline
              Kornfeld Eliyahu PeterK Offline
              Kornfeld Eliyahu Peter
              wrote on last edited by
              #6

              Glad to help...

              I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

              "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups