Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hook into Application_Start in a HttpModule

I’m implementing a simple HttpModule, where I want some code to run when the web application is started. But I’m surprised to find that the Application_Start event I would normally use from Global.asax is not available from a HttpModule. Is that correct, or am I missing something here?

How do I hook into the Application_Start event from an HttpModule?

Update:
I’ve come to simple solution using the Init event instead, but it still smells a bit funny to me.

like image 516
Jakob Gade Avatar asked May 06 '10 07:05

Jakob Gade


People also ask

What is Application_Start?

The Application_Start method is called only one time during the life cycle of an application. You can use this method to perform startup tasks such as loading data into the cache and initializing static values. You should set only static data during application start.

What is the use of HttpModule?

An HttpModule is a component that is part of the ASP.NET request processing pipeline and is called on every request that is made to your application. Note that HttpModules can have access to the life cycle events of a request and hence they can be used to modify the response as well.

What is HttpModule?

An HTTP module is an assembly that is called on every request that is made to your application. HTTP modules are called as part of the ASP.NET request pipeline and have access to life-cycle events throughout the request. HTTP modules let you examine incoming and outgoing requests and take action based on the request.

What is HttpModule MVC?

HttpModule are called before and after the request handler executes. They are intended to enable a developer to intercept, participate, or modify each request. There are 22 available events that can be subscribed to that enables the module to work on the request in various stages of the process.


1 Answers

I got interested in this thread and how a website started while fixing an bug in an old ASP.NET site.

So I put together a demo, to see how it would work. Seems the order IS from the web.config.

You can see here https://github.com/jradxl/MVC-Website-Without-Global.asax.cs It implements Robert Koritnik solution - thanks

like image 78
jradxl Avatar answered Oct 17 '22 06:10

jradxl