Found that many friends like me, mistakenly take ihttpmodule.init as a substitute for Application_Start, in which do some application initialization operations.
But in fact Ihttpmodule.init and Global.asax in the Application_Start event nature is different, can not directly take Ihttpmodule.init to replace Application_ Start is the asp.net application initialization process. It is also not easy to use the Init method to be repeated to determine that the ASP.net program has been restarted.
The reason is that ihttpmodule.init is likely to be repeated multiple times in response to a asp.net request, which is most likely to occur during the actual web site operation.
Why is ihttpmodule.init called multiple times? Because each HttpApplication instance can handle only one request at a time. While ASP.net supports certain concurrent requests, instances of HttpApplication are created multiple to respond to different requests when they are not responding to concurrent requests, and each HttpApplication instance creates a new set of HttpModule and invokes the Init method when it is created.
Application_Start will only be invoked after the first HttpApplication object is created, and subsequent HttpApplication instances will not trigger this event.
I think the reuse of HttpApplication instances is one of the main reasons why the use of the Init method of IHttpModule is misunderstood, because normally we have only one request to debug a program, and it is virtually impossible to duplicate the HttpModule init method. And in the actual Web site running environment, concurrent requests are very common, if the misuse of the Init method, may cause the program in the actual environment of strange problems.
For details, refer to the MSDN ASP.net Application Lifecycle overview for IIS 5.0 and 6.0, and the following are the pictures provided in the article: