C# ASP.NET HttpModules: HttpApplication Events

asp.netchttpapplicationhttpmodule

I have an HttpApplication (Global.asax) in my web application, I use this to catch and log unhandled Exceptions and to setup WebFormURLRouting. This all works, however I want to move this code into my Application Framework, (ie not in Global.asax.cs)

I have just tried to create an HttpApplication class in the framework but it seems I cant override the Events? Anyway I believe I can use an HttpModule instead to use consume these events, does this:

1) Eliminate the need for the Global.asax completely?

2) How does this effect scaling up, ie eventually running the application on a web farm

3) I have HttpHandlers to handle other things like File Uploading and File downloading, is there a limit to how many HttpModule/HttpHandlers should be used or should these be combined somehow to reduce overhead?

Any comments appreciated

Best Answer

Listening to the events you know from Global.asax, in an HTTP module, is as simple as hooking up to the events of the HttpApplication instance in the module's Init method. You cannot override the methods of the HttpApplication, you should listen to it's events.

As for your other questions: 1) Yes, in many of my web projects, we do not use a Global.asax

2) This does not really affect up-scaling. For each web server in the farm, you would need to have your HTTPModule hooked up correctly. But since this is done in web.config, it should be there already.

3) Short answer: No. For httphandlers, they are selected and run based on the incoming http request file extension and/or path and HTTP method. You would really need a lot of these before the selection of a specific handler becomes a performance issue. For HttpModules, you have the option of running some code at each request, and obviously, if that code takes time to run, it will affect performance. But it will be your code that takes the time, not the fact that it is being run via a http module.

Related Topic