Handling Application.Start via Custom HTTP Module

Handling Application.Start via Custom HTTP Module

am 23.04.2008 09:55:26 von Peter Schwartz

Using ASP.NET 3.5: Can a custom HTTP Module be used to register for the
Application_Start event? Or _must_ I use Global.asax to work with
Application.Start?

I understand that I can use a custom HTTP Module to register for other
pipeline events (like Application.BeginRequest), but I was told that the
only place that I can set up an event handler for Application.Start is in
Global.asax.

My preference would be to register an HTTP Module in Web.config that, upon
its initialization, has logic that determines if Application.Start needs to
be handled, and if so, which class and method (that I load dynamically into
the application's default AppDomain) is to handle Application.Start.

So, ideally, things would go like this (please tell me if you see any
problems with doing things this way):
1. When the application is first started, a custom HTTP module is loaded
(per Web.config).

2. That custom HTTP module has logic that determines if Application.Start is
to be handled.

3. If runtime conditions dictate that Application.Start is to be handled,
then the HTTP module proceeds to load the correct assembly, instantiate the
correct class, and register the correct Application.Start event handling
method with the Application.Start event.

4. The Application.Start event is then raised, thereby invoking the event
handling method wired up in step 3 above.

For the above to work, I would have to rely on somethig that I don't quite
understand... and that is the sequence of activities that take place when an
ASP.NET application is started: in particular, I would need to be able to
count on my custom HTTP module being loaded *before* Application.Start is
raised. Can I count on that sequence?

Your feedback and comments are appreciated!