Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 08, 2013 09:56 AM by manight
Dec 26, 2012 10:34 AM|LINK
When calling an URL without document, like for example http://www.yoursite.com IIS triggers a request to http://www.yoursite.com/Default.aspx (or whatever def document you set).
So even if your page is empty you will trigger 2 requests.
Asp.net Site here http://www.asp.net/whitepapers/aspnet4/breaking-changes in the section "Event Handlers Might Not Be Not Raised in a Default Document in IIS 7 or IIS 7.5 Integrated Mode" , states that "For default document requests, the first request is to
an extensionless URL. Therefore, IIS does not run any managed modules that are marked with a precondition of managed Handler during initial request processing."
But that's not true. Even with my HttpModule marked with attribute precondition="managedHandler" with a request like http://www.yoursite.com/ it still gets triggered two times (one for / and one for /Default.asp).
I'm I missing something or it's a bug?
I also set in web.config <modules runAllManagedModulesForAllRequests="false"> and <validation validateIntegratedModeConfiguration="true" />
Jan 07, 2013 07:26 PM|LINK
It depends on what module event your module handler hooks. Some events fire sooner than others. BeginRequest most likely fires for both, but anything closer to the actual HttpHandler's execution (ie the ASPX Page Handler) won't fire because the request
actually is redirected via URL Routing. So BeginRequest probably fires but PreRequestHandlerExecute probably does not on that first / request.
I'm not 100% sure at which point Url Routing/Default Document Redirection hooks into the IIS Pipeline, but it's probably after the first few module events have fired.
+++ Rick ---
Jan 07, 2013 09:12 PM|LINK
Hi rstahl, thanks for your reply.
I hooked for the test on PostAuthenticate request. What I did is very simple.
- I created a static variable, let's call it "debug", as a string.
- On post authenticate request I read the file path of the request and add it to the static variable with a "<br />" also
- In the default.aspx page I just print the variable on screen
Even with a blank page, just printing the variable you will always have on each request for the
www.site.com without the /default.aspx
Jan 07, 2013 09:56 PM|LINK
Ok I did a little more checking and you're right by default modules will fire twice both for the extensionless URL and default.aspx.
The default document module is an unmanaged module in IIS and it should preprocess and fire immediately even before the request lands in the ASP.NET pipeline.
However, in recent versions of ASP.NET there's another module that interferes with this behavior and actually precedes the default document handler which is the ExtensionlessUrlHandler which is meant to let you handle extensionless URLs in MVC and WebAPI
and other applications that take advantage of Routing.
That handleer is optional, but highly recommended if you're using any sort of routing like in MVC or WebAPI.
To turn it off you can use:
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
When I do this I never see the original URL hitting my .NET only modules.
Jan 07, 2013 10:58 PM|LINK
Thank you rick! This makes sense... By the way now I made a little filter in my modules based on extensions wich will bypass them so it won't be a big hit even if request triggers twice.
By the way (since I will need url rewriting at some point in my application even if it's web forms) I will do some testing removing the new modules.
Thank you for your deeper look at the issue. Maybe it could be useful to tell Microsoft about this? I don't think it's intended, maybe they'll fix in future releases.
Jan 07, 2013 11:31 PM|LINK
I don't think that's a bug it's by design. The Extensionless URL handler is meant to override extensionless URL behavior especially for MVC/Web API scenarios that require routing. The overhead of hitting the default pipeline twice is pretty minimal. Unless
your module does heavy duty work that affects overall performance (which would still be an issue hitting the ASPX page as well) it really shouldn't make much of an impact.
As a general rule modules should always perform careful checks of the requests they operate on and if the functionality doesn't apply immediately skip out.
There's some related info in this post:
Jan 08, 2013 09:56 AM|LINK
Yes that's what I ultimately did with:
' Skip the module if not a file of the extension allowed
If CoreHelpers.SkipHttpModule(request, ".aspx.axd") Then
Public Shared Function SkipHttpModule(request As HttpRequest, fileList As String) As Boolean
Dim currentLoweredExtension As String = request.CurrentExecutionFilePathExtension.ToLower
If String.IsNullOrWhiteSpace(currentLoweredExtension) OrElse InStr(fileList, currentLoweredExtension) = 0 Then