Hook into Application_Start in a HttpModule

前端 未结 6 501
太阳男子
太阳男子 2020-12-16 02:13

I’m implementing a simple HttpModule, where I want some code to run when the web application is started. But I’m surprised to find that the Application_Start event I would n

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-16 02:21

    As a matter of fact, there is, and always will be only one instance of specific http module until application pool recycle. And, of course, per w3wp.exe worker of you web application.

    In other words, use init method or constructor to do initialisation, preload data etc. ;) and don't use static fields except you need to do locking once requests start firing events your module subscribed to and you need change data your module controls or contains as properties. Anyhow, init method is called on application start.

提交回复
热议问题