When to use Application_Start vs Init in Global.asax?

后端 未结 2 1110
夕颜
夕颜 2020-12-04 12:16

I am wondering under what circumstances I should be putting application initialisation code in Application_Start() vs Init() in my Global.asa

相关标签:
2条回答
  • 2020-12-04 12:27

    From the MSDN docs:

    The Application_Start and Application_End methods are special methods that do not represent HttpApplication events. ASP.NET calls them once for the lifetime of the application domain, not for each HttpApplication instance.

    Init:

    Called once for every instance of the HttpApplication class after all modules have been created.

    UPDATE: if you need to make sure a certain code is called only once in the app. lifecycle, Application_Start is a better solution. Examples: configuring log4net?

    0 讨论(0)
  • 2020-12-04 12:41

    Yes

    There are differences between them. Application_Start() event is called just one time while Init() method is called on each time when instance of the application is created.

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