« Previous Next »

Thread: Custom HttpModule configuration - bug with managed requests

Last post 08-17-2009 3:20 PM by literadesign. 3 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (4 items)

Sort Posts:

  • 08-12-2009, 3:55 PM

    Custom HttpModule configuration - bug with managed requests

    I'm running Asp.net MVC application. By default web.config sets all modules to run for all requests which I disabled. I have a custom HttpModule that's responsible for authentication of managed requests.

    Part of my web.config looks like this:

    <modules>
       <add name="CustomAuth" type="..." preCondition="managedHandler" />
    </modules>

    Then I try to access my site via http://localhost/default.aspx
    All works fine. My Handler gets invoked since IIS integrated pipeline thinks it's managed request. Great.

    Then I try to access my site via http://localhost/
    Suddenly IIS7 thinks this is <b>not managed request</b>. So I put default.aspx on top of Default documents, to convince IIS that this is in did managed request, but to no avail... This should be treated as managed content that's why it's a bug. I should also mention that I'm running NetFx 3.5 SP1. I read elsewhere that this bug didn't exist in previous versions.

    So I would like to:

    • configure IIS (via management UI or web.config) to run modules certain modules only for managed requests and not for static content as well
    • avoid configuring running all modules on all requests

    I guess the culprit is StaticFile module. Could I use UrlRewriting module because (AFAIK) it executes before StaticFile module? Any other suggestion?

    Robert Koritnik
  • 08-17-2009, 6:05 AM In reply to

    Re: Custom HttpModule configuration - bug with managed requests

    Hi,

    If you access your site via  http://localhost, the child request http://localhost/default.aspx will be generated. Hence, the custom HttpModule should also be invoked for the request http://localhost.

    Could you capture a Failed Request Tracing log to determine the root cause?

    Leo Tang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • 08-17-2009, 1:58 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 6:13 PM
    • Redmond, WA
    • Posts 2,343

    Re: Custom HttpModule configuration - bug with managed requests

    Like Leo said, a request to http://localhost results internally in 2 requests being executed, one for http://localhost and the other for http://localhost/default.aspx - the first request is not considered managed, so your module is not loaded for it, and therefore the request fails due to the url authorization rule.  Possible fixes would be to (a) move the url authorization rules to the asp.net urlauth section so they only apply to asp.net content (b) Bring back runAllManagedModulesForAllRequests (or at least remove pre-condition from your module) so that both authentication and authorization happen for all requests.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 08-17-2009, 3:20 PM In reply to

    Re: Custom HttpModule configuration - bug with managed requests

    Leo Tang - MSFT:

    Hi,

    If you access your site via  http://localhost, the child request http://localhost/default.aspx will be generated. Hence, the custom HttpModule should also be invoked for the request http://localhost.

    Could you capture a Failed Request Tracing log to determine the root cause?

    Well the thing is, it doesn't. I'd expect it do that as well, but it doesn't. At least not in NetFx 3.1 SP1. You can try it out yourself. Create a module that will handle whatever app event and set preCondition="managedHandler". You'll see it doesn't execute on folder requests.

    What resolved this issue was configuring a complete list of handlers in my web.config file, that overrode applicationHost.config file settings. I copied original content (handlers node) from applicationHost.config file to my web.config and just before the last entry (StaticFile) I added bunch of my own settings:

    <add name="StaticFile-jpg" path="*.jpg" verbs="*" module="StaticFileModule" resourceType="File" requireAccess="Read" />
    <add name="StaticFile-gif" path="*.gif" verbs="*" module="StaticFileModule" resourceType="File" requireAccess="Read" />
    <add name="StaticFile-css" path="*.css" verbs="*" module="StaticFileModule" resourceType="File" requireAccess="Read" />
    ...
    <add name="StaticFile-js" path="*.js" verbs="*" module="StaticFileModule" resourceType="File" requireAccess="Read" />
    <add name="DirectoryHandler" path="*" verbs="*" type="System.Web.UI.PageHandlerFactory" resourceType="Either" requireAccess="Read" />

    Static files are added to actually exclude static files from managed pipeline, and the last one before StaticFile is used ot execute managed handlers on folder requests as well. After this block, there was the default StaticFile entry that handles all the rest.

    And regarding your Failed request tracing... My request doesn't fail. It gets served, it just doesn't execute modules with preCondition set as per above...

    Robert Koritnik
Page 1 of 1 (4 items)
Microsoft Communities