Application_AcquireRequestState Execute twice per request

Code inside of the global.asax file on the Application_AcquireRequestState event fires twice for each request. One the first request I have session state and on the second, I do not.

Here is simple test I ran to verify that it is running twice:

    Protected Sub Application_AcquireRequestState(ByVal sender As Object, ByVal e As System.EventArgs)
        If Request.IsAuthenticated Then
            System.Diagnostics.Debug.Print("Inside Application_AcquireRequestState")
        End If
    End Sub


If I try to referrence a session variable in the event, the first time it execute, I'm okay. On the second event, I get an error indicating that Session state is not available in this context.

Can anyone explain this or suggest how can I ensure that this event is only fired once



Answer this question

Application_AcquireRequestState Execute twice per request

  • Josh Zana

    change autoeventwire up to false from true in your page html code.

    AutoEventWireup="False



  • Sandy L

    It is in the global.asax file. And I was wrong - the event fires several times.
  • aao123

    Did you get any help with this I have the same issue.

  • Jude Landry

    No, unfortunately I did not. I was using Beta 2 and thought that may be it was just a beta bug that would be fixed by the release. I haven't been able to get back to looking at yet. Let me know what happens as I will you as well.
  • wbartussek

    I had to do this:

    If Not System.Web.HttpContext.Current.Session Is Nothing Then

    'YOUR CODE HERE

    End If

    All this does is makes sure that session is available when your code executes. NOTE: I had to fully qualify (namespace) where to find Session for this to work right. I do not have any idea why, but I tried to import the name space and it still didn't work. I would like someone to answer that question...

    Richard


  • Andrew Petrochuk

    Are you accessing a .aspx or .asmx page
  • SVerhalle

    This works!. Even though the AcquireRequestState gets fired multiple times, the code in inside of the IF condition is only executed once.

    Did you try importing the system.web namespace When I did that, I was able to shorten it statement to If not HttpContext.Current.Session is nothing ion by itself.

    David


  • ClarkMe

    Please post ASP.NET specific questions to the ASP.NET web forums:

    http://forums.asp.net

    Daniel Roth

  • Application_AcquireRequestState Execute twice per request