I have some logic I would like to execute in the Application_Start, but instead of having to add this to the Application_Start in Global.asax.cs, is there I way I can add an entry into the web.config to execute it in the exact Application_Start?
Asked
Active
Viewed 1,469 times
3 Answers
1
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.

Steven V
- 16,357
- 3
- 63
- 76
-
Is the BeginRequest the same as Application_Start? – TruMan1 Feb 25 '13 at 01:04
-
@TruMan1 BeginRequest would be fired at the beginning of _every_ request to your application. So every time someone visited the application. Application_Start would be when your application starts up after the App Pool recycles (configuration change, binary change, etc.) and would fire once, no matter how many web requests are received. – Steven V Feb 25 '13 at 01:08
-
Also the HTTP module events fire multiple times such as the init. Seems like the only place to get it run once and only once is the global.asax.cs. – TruMan1 Feb 25 '13 at 01:22
-
@TruMan1 You could use the Init() function to do what you want. Though be careful, since it is possible for the Init() function to be called multiple times. Take a look at http://stackoverflow.com/a/3378584/254973 to get more information. But this may start getting into overkill area. Seriously, take a look at WebActivator which you can tie into many parts of the web application startup process, without reinventing the wheel. – Steven V Feb 25 '13 at 01:34
0
You could perhaps created an initaliser in app_start that looks at the web config and loads up your various tasks that you want to start

Daniel Powell
- 8,143
- 11
- 61
- 108
0
there are different ways of doing that, one simple way is
- create a entry in web.config for the class/interface that will be doing the job.
- put the actual implementation of that class
- in Application_Start, load the value from web.config, create a instance of the class using reflection or whatever you can think of e.g. http://msdn.microsoft.com/en-us/library/system.activator.createinstance.aspx
- 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

Stay Foolish
- 3,636
- 3
- 26
- 30