Why is HttpApplication constructor called several times

前端 未结 2 517
独厮守ぢ
独厮守ぢ 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: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.

提交回复
热议问题