简体   繁体   中英

How to hook into Application_Start from Web.config?

我有一些逻辑要在Application_Start中执行,但是不必将其添加到Global.asax.cs的Application_Start中,我可以在其中添加一个条目到web.config中以完全执行它Application_Start?

Specifically from the web.config, you could create a HTTP Module that would hook into the start of the application.

Also depending on your setup, you could use the WebActivator ( Nuget ) which would allow you to hook into the Application_Start event at runtime.

您也许可以在app_start中创建一个初始化程序,该初始化程序查看Web配置并加载要启动的各种任务

there are different ways of doing that, one simple way is

  1. create a entry in web.config for the class/interface that will be doing the job.
  2. put the actual implementation of that class
  3. in Application_Start, load the value from web.config, create a instance of the class using reflection or whatever you can think of eg http://msdn.microsoft.com/en-us/library/system.activator.createinstance.aspx
  4. call the function in that class that will actually perform the logic.

Or you can use some other technology like dependency injection and inject the actual implementation from the web.config

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM