locked
HttpModule execute order RRS feed

  • Question

  • User1410283980 posted

    Hello!

    Just a simple question...

    I've got a ASP.NET WebApp configured with Forms Authentication. If I add an HttpModule to its web.config, which one will fire first, on every request: the FormsAuthenticationModule or my custom HttpModule?

     
    Thanks
     

    Friday, April 20, 2007 11:26 AM

Answers

  • User1439985827 posted
    ASP.NET Fires them the order they are defined in the web.config. Since the FormsAuthenticationModule is defined in the machine.config file, it will be executed first. If you don't want it, you can remove it. Or if you want to re-order it, remove it, add your own, then add it back.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 20, 2007 7:16 PM

All replies

  • User1439985827 posted
    ASP.NET Fires them the order they are defined in the web.config. Since the FormsAuthenticationModule is defined in the machine.config file, it will be executed first. If you don't want it, you can remove it. Or if you want to re-order it, remove it, add your own, then add it back.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 20, 2007 7:16 PM
  • User-225114762 posted
    If at all possible, avoid depending on the order of execution of HttpModules. I'm not at all sure that ASP.NET actually guarantees the order of execution, even if it does, it's still not good programming practice since it's very brittle and will break, probably silently and undetectably, if anyone by mistake changes something in the external configuration - i.e. Web.Config. Use the well-defined order of events to control the exeuction.
    Sunday, April 22, 2007 7:37 AM
  • User-702887943 posted
    I hope someone is still reading this thread... What if you have two distinct modules that subscribe to the same application event (let's say BeginRequest)? How can you guarantee that the delegates are executed in a specified order? Thanks, Paolo
    Wednesday, March 18, 2009 1:13 PM
  • User1622957740 posted

    As somebody else pointed out you should never rely on the order of modules in the chain.

    If you have dependencies and specific orders you need to handle in your own modules then you probably need to consolidate those modules into a single module and handle the order through your own code internally.

    +++ Rick ---

    Wednesday, March 18, 2009 3:28 PM
  • User-702887943 posted
    Thanks Rick, it seems the most sensible thing to do. Paolo
    Wednesday, March 18, 2009 7:18 PM