locked
Http Module hit on every request for a resource - why ? RRS feed

  • Question

  • User1796289523 posted

    I am developing a http module that hooks into the FormsAuthentication Module through the Authenticate event.

    While debugging i noticed that the module gets hit every single time the client requests a resource (as expected the first request for the page, but also when it requests images, stylesheets, javascript files).


    I dont want it to hit all the modules registered for the website on every single request. How do i turn it of ?


    I am running VS 2008 on Windows Vista when debugging, and using MVC and its routing mechanism if that can have anything to do with it.

    When i check HttpRuntime.UsingIntegratedPipeline it returns false (soo it shouldnt be problem). Also to make sure it isnt the IntegratedPipeline i have set runAllManagedModulesForAllRequests to false in the web.config to ensure this shouldnt happen, and the modules in the iis 7.0 (system.webServer) section is registered with the managedHandler precondition.

    As far as i know calling the modules for requests which isnt handled by the asp handler was something that was introduced with iis 7.0 and the integratedpipeline mode, soo what is happening shouldnt even be possible when not running in integrated mode. Only thing i can come up with is that the handler of gif, jpg, css, js is the same as the asp handler, but i dont know where to look for checking this (i havent changed any handlers from the default setup).

    Could it be the routing mechanism (UrlRoutingModule) which needs to be called on every request, which also makes it call all other modules on every request?


    Martin

     

     

     

    Friday, October 2, 2009 11:45 AM

All replies

  • User-627724879 posted

     If you are seeing this with WebDev (the web server that executes by default in VS) then yes all requests are processed by the server using the ASP.NET engine. In IIS you have to explicitly map all the file types to be processed by ASP.NET. So unless you explicitly set .jpg, .css, etc to be processed by ASP.NET this will not be the case.

    Friday, October 2, 2009 12:38 PM
  • User1796289523 posted

    Thanks for your reply.

    I have just tested some more.
    I got the problem both when using WebDev and on a IIS 7 server.

    When running IIS 7 with the runAllManagedModulesForAllRequests set to true, all modules get called by the event that they hook into on every single request (just like the attribute name is indicating).
    If i set runAllManagedModulesForAllRequests to false no module at all will get called (including all the standard asp.net modules). If i remove the preCondition="managedHandler" then the module without the preCondition will be called on every single request.

    when runAllManagedModulesForAllRequests is set to false and the preCondition set to managedHandler I would have expected it to hit the module only when a page served by ASP.NET handler, but it never calls anything.

    It seems this is because of the routing module as it never hits an aspx page.
    That is what i suspect right now because if i call "mydomain.com/Default.aspx" instead of just the root like "mydomain.com/" then it runs all the modules only once like it is supposed to.

    Is there any way i can fix this ?

    I need to somehow make sure that specific filetypes are not handled by the asp.net handler.
    But i guess this will again be a problem if i go with urls like /Img/TheImage for images (etc) and not use the extension.

    Can this be defined in IIS somehow or when setting up the routes for the website (i have tried with IgnoreRoute but havent been succesful) ?

     

     If you are seeing this with WebDev (the web server that executes by default in VS) then yes all requests are processed by the server using the ASP.NET engine. In IIS you have to explicitly map all the file types to be processed by ASP.NET. So unless you explicitly set .jpg, .css, etc to be processed by ASP.NET this will not be the case.

     

     

    Friday, October 2, 2009 6:32 PM