locked
The init() being called several times in httpmodule RRS feed

  • Question

  • User-730945238 posted

    Hello

    I have a HttpModule in which Autenticate Request event for the custom code to run.It has  a static constructor which initializes some values.Also at the start of the event code I check for a spcial page by checking the page name in the URL and if present I want the code to pass through without proceeding further in the event code.I have 2 questions.

    1.The contructor is static so does that mean that it will be called just once unless the app pool or web app is recyled.I am using caching to cache some content which gets initialized in the constructor but since it is not even calling the constructor again unless I recycle the app pool I m not sure whether caching is of any use here.

    2.For the same requests the Init method is called several times for different urls like Images etc.But what I want is as soon as it detects the special it should just move on .

    Thanks

    Monday, August 27, 2012 3:00 PM

Answers

  • User1779161005 posted

    1.The contructor is static so does that mean that it will be called just once unless the app pool or web app is recyled.I am using caching to cache some content which gets initialized in the constructor but since it is not even calling the constructor again unless I recycle the app pool I m not sure whether caching is of any use here.

    Correct.

    2.For the same requests the Init method is called several times for different urls like Images etc.But what I want is as soon as it detects the special it should just move on .

    The runtime creates many instances of http modules. This way the runtime can use one http module per thread if multiple requests are being executed. Under the covers these instances are pooled and created/destroyed based upon demand.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 27, 2012 3:09 PM