tags:

views:

176

answers:

2

Is there a way to handle the application_start "event" without using the global.asax?

The best I can come up with is an HttpModule that checks some static variable on every begin_request, which is INCREDIBLY wasteful :(

Do I have any other options?

Thanks

A: 

AFAIK, the reflection-based "pseudo-events" in Global.asax are not accessible in any other way than by reflection. However, for the application_start event, you might be able to achieve similar functionality by overriding the Init() method on a subclass of HttpApplication. Some functionality might not be accessible, as it probably fires on a slightly different point in the lifecycle.

Alternatively, if you're going with an HttpModule, couldn't you just use the Init() method instead of begin_request?

Jonas H
no because there are a pool of HttpModules, they arent instantiated as singletons, each requests could in theory get a new instance.
Andrew Bullock
admittedly this approach would be less wasteful than begin_request, but its still, not ideal
Andrew Bullock
A: 

If your code is existing in the website, you can use the largely undocumented 'AppInitialize' method. Add this static method to any class in your web project.

(Note: it will not work if contained in a compiled assembly within the site.)

For more info, search for "AppInitialize". (Ex: http://www.bing.com/search?q=appinitialize+msdn&src=IE-SearchBox&FORM=IE9bSRC)