Last post May 24, 2006 03:39 PM by praveeny
Apr 19, 2006 01:26 PM|JeffSpicolie|LINK
I have read a couple of other post here with a similar type of issue but there never was an outcome. Everyone though the poster's were crazy it seemed. So, that being said, let me join the crazies...
In an HttpModule I add an event handler like so;
Why would the OnAquireRequestState method fire 2 times when debuggin in an HttpModule. The module errors the second time when calling the HttpContext.Session object with a NullReferenceException here;
The Content Page (aspx) inherits from a base page which adds 2 event handlers (this is closer to the core of my issue I feel);
' Register the PreInit
When I implement a Master Page into the mix, OnAquireRequestState is fired 7 times. Once again erroring all times with NullReferenceException when calling HttpContext.Session object.
So, without the master page and base page, it works, fires once with success. Base Page fires twice, base page with master page fires seven times...
It is most certainly a very basic concept on page event execution that I am missing here, and my discription, with my record, is vague, but all being said do any lights go off in anyone's head here, because I feel like I am in the dark of night in the Amazon?
Many thanks for any insight, or slaps to the back of the head as well! :)
Apr 20, 2006 01:07 AM|ScottGu|LINK
Are you running the application using the built-in VS 2005 Web Server? If so, then you are probably seeing this called multiple times because the static file resources (CSS files and images) are processed by the built-in web-server -- in which case they
will each fire them as well.
Hope this helps,
Apr 20, 2006 12:27 PM|JeffSpicolie|LINK
Let me first say thanks for taking the time out to answer my post. Let it be known that I feel special that "ScottGu" communicated with me! Love the work you do (read your blog regularly and I am honored! Keep up the great writting! ;)
That does help because I am running in debug mode in VS 2k5 within the built in web server.
I changed the code to handle the Null Ref in the AquireRequestState event handler and it seems to work around the problem;
Does that make sense to do? It stills freaks me out to watch that event fire 2-7 times though. This will not happen outside of VS, say in a production
environment would it?
Many thanks Scott!
Apr 21, 2006 11:27 AM|ScottGu|LINK
Haha -- glad I could help. ;-)
Yep -- the above code looks like it will work fine to me.
This wouldn't have on a production IIS environment assuming that static files aren't mapped to IIS (which by default they aren't). It is only happening with the built-in web-server because it is configured to process all requests to the site.
May 24, 2006 03:39 PM|praveeny|LINK
I was working on this with one of our customers and while debugging the code we found out that one of the requests going back to the server was for the webresource.axd file. Now the webresource.axd is a handler
which is designed to retrieve assembly resources and serve them to the web browser. These resources could be any static files embedded within the assembly itself. For example, the WebUIValidation.js (used by the validation controls) is now a part of the system.web.dll.
So the number of times the OnAcquireRequestState is fired depends on the number of embedded resources we are getting from the server.
Since this is just a AseemblyResourceLoader there is no session associated with it and we see the null value when we try to get the Session object.
To workaround this problem we can check the URL and verify if it has an extension of ".axd" and return from there. For example
if InStr(HttpContext.Current.Request.Url.AbsoluteUri, ".axd") > 0 then
Here is an article i wrote a while back on web resources.
Hope that helps!!!