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" />
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.
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.
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
/
/default.aspx
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.
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.
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.
' Skip the module if not a file of the extension allowed
If CoreHelpers.SkipHttpModule(request, ".aspx.axd") Then
Exit Sub
End If
And
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
Return True
End If
Return False
End Function
Member
20 Points
70 Posts
HttpModule triggered two times for request to URL without default document
Dec 26, 2012 06:34 AM|manight|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" />
Participant
1471 Points
442 Posts
ASPInsiders
MVP
Re: HttpModule triggered two times for request to URL without default document
Jan 07, 2013 03:26 PM|rstrahl|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 ---
West Wind Technologies
Making waves on the Web
weblog.west-wind.com
Check out: Markdown Monster
Participant
1471 Points
442 Posts
ASPInsiders
MVP
Re: HttpModule triggered two times for request to URL without default document
Jan 07, 2013 03:26 PM|rstrahl|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 ---
West Wind Technologies
Making waves on the Web
weblog.west-wind.com
Check out: Markdown Monster
Member
20 Points
70 Posts
Re: HttpModule triggered two times for request to URL without default document
Jan 07, 2013 05:12 PM|manight|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
/
/default.aspx
Participant
1471 Points
442 Posts
ASPInsiders
MVP
Re: HttpModule triggered two times for request to URL without default document
Jan 07, 2013 05:56 PM|rstrahl|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:
When I do this I never see the original URL hitting my .NET only modules.
+++ Rick ---
West Wind Technologies
Making waves on the Web
weblog.west-wind.com
Check out: Markdown Monster
Member
20 Points
70 Posts
Re: HttpModule triggered two times for request to URL without default document
Jan 07, 2013 06:58 PM|manight|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.
Participant
1471 Points
442 Posts
ASPInsiders
MVP
Re: HttpModule triggered two times for request to URL without default document
Jan 07, 2013 07:31 PM|rstrahl|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:
http://www.west-wind.com/weblog/posts/2012/Oct/25/Caveats-with-the-runAllManagedModulesForAllRequests-in-IIS-78
West Wind Technologies
Making waves on the Web
weblog.west-wind.com
Check out: Markdown Monster
Member
20 Points
70 Posts
Re: HttpModule triggered two times for request to URL without default document
Jan 08, 2013 05:56 AM|manight|LINK
Yes that's what I ultimately did with:
And