Why is HttpApplication constructor called several times

前端 未结 2 514
独厮守ぢ
独厮守ぢ 2021-02-07 01:28

Can somebody explain why the constructor of a custom class derived from HttpApplication is called several times upon application startup?

My code struct

相关标签:
2条回答
  • 2021-02-07 01:46

    Please have a look at a post global.asax in ASP.NET - it explains why there are multiple instances of the HttpApplication. Basically there are two pools: special and normal. Normal pool contains instances of the HttpApplication which are used by the requests (each requests has its own HttpApplication instance). Special pool contains HttpApplication objects used for application-level events (like Application_Start, Application_Error).

    0 讨论(0)
  • 2021-02-07 01:55

    I believe the ASP.NET runtime may create more than one HttpApplication per application domain. So HttpApplication.Init and the Ctor may get called more than once.

    If you want to have initialization code that only runs once, you should use the Application_Start event which will only be called once per app.

    0 讨论(0)
提交回复
热议问题