The reason that the Ihttpmodule.init method was executed several times

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.