I'm creating a library that needs to run some code at various stages of the ASP.NET request lifecycle.
It's easy to do this when writing a web application by overriding HttpApplication.Init() and registering various handlers there.
However, I want to do this from my library during Application_Start(); I don't want to consumer to have to override Init() and call my event setup code from there.
Is there any way to achieve this?
Here's my ideal setup:
// in the consumer's code
protected void Application_Start()
{
// should ideally be able to register lifecycle event handlers from the line below
MyLibrary.Configure(...);
}
You should just be able to do
global.asax
This here, refers to the application and there are plenty of events you can subscribe to on it including request life cycle events