Can someone explain in less than 2 sentences the difference between both? Yes, I know google can provide hundreds of answers but not one in 2 clear sentences:)
-
In the context of looking to run some code before every request. – frenchie Jun 23 '11 at 03:56
-
24+1 for the "yeah I know I can Google it". – Csharp Jan 08 '13 at 22:36
-
7"Less than two sentences." Like, one sentence? – Andrew Theken Dec 04 '15 at 13:38
8 Answers
HttpHandler is where the request train is headed. HttpModule is a station along the way.

- 7,241
- 3
- 24
- 26
-
-
-
6
-
9Nice. I would add that HttpContext is the train. Every station (Module) contributes to HttpContext in some way as it passes by. – Duanne Jun 16 '16 at 14:48
-
-
The two sentences:
An HttpModule will execute for every request to your application, regardless of extension, and is generally used for things like security, statistics, logging, etc.
An HttpHandler is generally associated with a specific extension, and is used for things like RSS feeds, dynamic image generation or modification, and the like.
A little more explanation if that's not completely clear:
The way I think about them - modules "plug in" to the request pipeline, whereas handlers "handle" a specific file extension. So, if you've got a site with a LoggingModule and a PdfHandler, both will execute for a request to http://example.com/sample.pdf, and the logging module alone will execute for a request to http://example.com/page.aspx.
There's a pretty clear article on the difference on MSDN: HTTP Handlers and HTTP Modules Overview

- 12,626
- 10
- 72
- 101

- 52,327
- 25
- 125
- 193
-
1ok, so if I want to run some code that runs on every request to an .aspx file I implement a handler and if I want to run some code on every request regardless of the type of file requested I implement a module. Is that it? – frenchie Jun 23 '11 at 04:19
-
5@frenchie - No, aspx pages are built on top of HttpHandlers by providing you with the Page Life Cycle. Think of it as an aspx page, cut down to the very basic event. `ProcessRequest`. The module on the other hand, will execute at any point in the life-cycle you wire it up to. For your scenario of wanting to run something prior to the aspx page, you want a module. However you need to manually filter out the requests to pages that are not .aspx – Phill Jun 23 '11 at 04:26
-
6Am I correct by saying that every request can have just 1 handler and multiple modules? – Maarten Kieft Jan 25 '13 at 12:11
-
1Is the general answer of handlers = state, and modules don't an unwritten standard or is there anything fundamentally different from the two, I mean, could a person code a module to be like a handler and vice-versa or are there limitations to them that make it impossible? – Rich Bianco Sep 10 '16 at 04:02
The prime and common goal of HttpHandler and HttpModule is to inject pre-processing logic before the ASP.NET request reaches the IIS Server.
ASP.NET provides two ways of injecting logic in the request pipeline;
- Http Handlers: Http Handler helps us to inject pre-processing logic based on the extension of the file name requested. ASP.NET uses HTTP handlers for implementing a lot of its own functionality.For example, ASP.NET uses handlers for processing .aspx, .asmx and trace.axd files.
example: RSS feeds: To create an RSS feed for a Web site, you can create a handler that emits RSS-formatted XML. So when users send a request to your site that ends in .rss, ASP.NET calls your handler to process the request.
There are three steps involved in creating Handler 1. Implement IHttpHandler interface. 2. Register handler in web.config or machine.config file. 3. Map the file extension (*.arshad) to aspnet_isapi.dll in the IIS.
IHttpHandler interface has ProcessRequest method and IsReusable property which needs to be implemented. ProcessRequest: In this method, you write the code that produces the output for the handler. IsResuable: This property tells whether this handler can be reused or not.
You can register the handler in web.config file like this
<httpHandlers>
<add verb="*" path="*.arshad" type="namespace.classname, assemblyname" />
</httpHandlers>
Note: here we are handling any file name with extension arshad.
- Http Modules: HttpModule is an event based processor to inject pre-processing logic before the request reaches the IIS Server. ASP.NET uses HTTP Module to implement lots of its own functionality like authentication and authorization, session management and output caching etc.
ASP.NET engine emits lot of events as the request passess through the request pipeline. Some of those events are AuthenticateRequest, AuthorizeRequest, BeginRequest, EndRequest. By Using HttpModule you can write logic in these events. These logic get executed as the events fire and before the request reaches IIS.
There are two steps involved in creating Modules, 1. Implement IHttpModule interface 2. Register module in web.config or machine.config file
example: Security: Using HTTP module, you can perform custom authentication or other security checks before the request reaches IIS.

- 379,657
- 97
- 704
- 746

- 361
- 3
- 4
HTTP handler is the process that runs in response to a request made to an ASP.NET Web application. HTTP modules let you examine incoming and outgoing requests and take action based on the request.

- 1,534
- 1
- 8
- 4
-
2
-
18Yes Frenchie..Open the code behind of any aspx. you will see: public partial class good : System.Web.UI.Page Now right click on Page and click Go to definition, you will see: public class Page : TemplateControl, IHttpHandler – Aditya Bokade Jul 06 '12 at 21:26
HttpHandler is responsible for handling http request by extension while HttpModule is responding to application life cycle events.

- 10,450
- 5
- 32
- 57

- 4,691
- 3
- 37
- 49
Nice article aboute it HttpModule-and-HttpHandlers
Reference: INFO: ASP.NET HTTP Modules and HTTP Handlers Overview
“Modules are called before and after the handler executes. Modules enable developers to intercept, participate in, or modify each individual request. Handlers are used to process individual endpoint requests. Handlers enable the ASP.NET Framework to process individual HTTP URLs or groups of URL extensions within an application. Unlike modules, only one handler is used to process a request”.

- 235
- 2
- 6
HTTP handler is where actually compilation is done based on setting. such as if page extension is .aspx then it will compile through system.web.Ui.Pagahandlefactory. once compilation is done at HTTP handle request will go though HTTP module and IIS.

- 20,698
- 67
- 109
- 136

- 19
- 1
HTTP Handler
HTTP Handler is the process which runs in response to a HTTP request. So whenever user requests a file it is processed by the handler based on the extension. So, custom http handlers are created when you need to special handling based on the file name extension. Let's consider an example to create RSS for a site. So, create a handler that generates RSS-formatted XML. Now bind the .rss extension to the custom handler.
HTTP Modules
HTTP Modules are plugged into the life cycle of a request. So when a request is processed it is passed through all the modules in the pipeline of the request. So generally http modules are used for:
Security: For authenticating a request before the request is handled.
Statistics and Logging: Since modules are called for every request they can be used for gathering statistics and for logging information.
Custom header: Since response can be modified, one can add custom header information to the response.

- 1,509
- 9
- 13