What is the performance difference between HttpModule and Global.aspx?

I created a web application in which I use a module that redirects without urls to ā€œwwwā€ ( http://example.com/ ) using ā€œwwwā€ urls ( http://www.example.com/ ). But since I am on a shared hosting server, where I do not have permission to deploy HttpModule, I tried the same module code with the Global.asax file. It works!

I used the following (Application_BeginRequest ()) event to implement my HttpModule functions.

void Application_BeginRequest() { //module code } 

The module and application work well and correctly from the Global.asax file. But I'm worried about performance.

Why we use HTTPModules in asp.net. If we can implement the same using the Global.asax file. Are there differences in performance between the two. Or is there any difference I need to worry about when using the Global.asax file instead of the HttpModule ??

Please explain!

+6
c # web-applications global-asax
source share
2 answers

Global.asax inherits from HTTPApplication, and HTTPModules must implement IHTTPInterface.
The HTTPModules Init method gets the passed HTTPApplication object.
In the Init method, you can connect to HTTPApplication events.

I would recommend using HTTPModules wherever you are.
Especially if you are making software shrink wrapped software where the customer can replace your global.asax with their own.

+4
source

To a large extent, there is no difference. The HTTPModules point is for clarity and separation. Often people will process the request through several HTTPModules, which you cannot get with global.asax.

+2
source

All Articles