Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 961765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:23:49+00:00 2026-05-16T01:23:49+00:00

Web application initialization is as follows: As we know when IIS receives the first

  • 0

Web application initialization is as follows:

  1. As we know when IIS receives the first request for a particular Asp.net application resource, IIS creates an instance of a HttpApplication (defined in global.asax codebehind).
  2. When this new instance is created it’s initialization happens that also checks all configured HTTP modules.
  3. All modules are then instantiated and put in the application’s Modules collection (of type HttpModuleCollection)
  4. modules are looped through and their Init() method is called (when they register for request events)

As far as I understand it the above scenario happens when a web application is started/initialized (hence application start event).

What happens with modules?

Are they (re)instatiated on each request or reused from the Modules property on each consecutive request while the web application is alive? As I understand IIS and Asp.net they are reused through the whole life of a web application.

If they are reused, can we assume that their Init() method is actually a pseudo event handler for application start event? The thing is we can’t attach to application level events within http modules. But if they are being reused we could use Init() as application start event and do whatever we’d put in global.asax instead.

Question

Can we assume that module’s Init() method is called only on application start event? Could we use this assumption to i.e. register routes for applications whose global.asax codebehind we can’t change? web.config is usually accessible and we can change it the way we want.
Would this actually work?

Additional info

We can check HttpApplication code and check its InitModulesCommon() method. This one actually calls Init() of each registered HTTP module. What is more interesting is that this method is only used by InitIntegratedModules() and InitModules() methods. Which are both used only in HttpApplication.InitInternal() method. This is the basis of my assumptions, but I would like to know whether someone has abused IHttpModule.Init() for application start event.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:23:50+00:00Added an answer on May 16, 2026 at 1:23 am

    Init() is called only once (per HttpApplication instance)

    After I tested this the inner workings of IHttpModule initialization are as follows:

    1. Every IHttpModule is initialized at web application start by instatiating and a call to Init() method
    2. HttpApplication stores all module instances in its Modules property
    3. Modules are then reused for the whole life of an HttpApplication and are not discarded/reinitialized as long as the application is alive

    So the best outcome is

    You can’t attach an IHttpModule to application level events, but you can use its Init() method as pseudo application start event delegate. Inside it you can execute any code that you’d usually put inside Application_Start delegate in your Global.asax.

    You can also read detailed information about it in my blog post.

    But be careful in real-life web server environment

    But IIS uses something called application pools. And each pool can have an arbitrary number of HttpApplication instances. Yes multiple. Application starting creates all these instances. Every one of them initializes their own list of modules but only the first one executes the Application_OnStart event handler.

    So whenever your module modifies some common shared resource, you should take extra measures to indicate that the first module has done that and others won’t do it again. Read an additional blog post about it that will show you how and when to use thread locking with your module to make it actually act as an Application_OnStart event handler. BTW: It’s also possible to handle Application_OnEnd event if you need to. 😉

    Detailed blog post links

    1. Writing a custom IHttpModule that handles Application_OnStart event
    2. How to correctly use IHttpModule to handle Application_OnStart event
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an ASP.Net Web Application that is running in an IIS Web-Garden--which is
During ASP.NET precompilation of our .NET 3.5 web application, various initialization is performed in
My web application is ASP.NET MVC4 with Razor and Knockout.js. The view model hierarchy
I have an ASP.NET 4.0 web application which uses a third-party API for external
I have MVC3 web application running under IIS 7. During initialization in global.asax application
We have an ASP.NET web application which uses ASP.NET Ajax. We open it from
I have a situation where I user IoC (WindsorContainer) in a .Net web application,
Where can I embed startup initialization code in a Restlet web application, without using
I have an ASP.NET application that uses the Fluorine FX remoting library. When the
I have an existing ASP.NET MVC application and am using StructureMap as my IOC

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.