Yesterday noon, in a middle of our department's technical conversation, I raised the issue of the difference between IHttpHandler and IHttpModule models, because I'm using an IHttpHandler logic model in a part of the application I working on.
Also I want to clarify OrenEllenbogen's (one of our team leaderes) findings. He claims, correctly, that the clothing of an application (Global.asax) is the IHttpModule that "hosts" several IHttpHandlers. Now, by the specific request that goes through the IHttpModule firstly, it knows to navigate it to the specific handler (IHttpHandler) to handle it.
Here, I want to go into details about those two nice and essential models.
HttpHandler - Every typical page (that derives from System.Web.UI.Page) implements the IHttpHandler interface. Writing an IHttpHandler is no different that writing typical page or control. It includes server application objects like: Session, Request and Response. An HttpHandler is created for each request to the server and its lifetime exists on the request ProcessRequest step. (It important to mention that this action happens before the page events are raised (like Page_Init, Page_Load etc...)
Another thing to know about HttpHandler behavior is the IsReusable property that defined in the interface. If this retured as true, the HttpHandler won't be destroyed when a control exits ProcessRequest - it will be released to the pool for future requestor. This means that request specific data must be de-initialized at the end of the request, or re-initialized at the begining of a request.
Nice example of use is Url Rewriting. We used a handler in previous a web application development that handles multi-lingual states (supports English and Hebrew languages). We wrote an HttpHandler that in every request to the server, checks the browser url, and by a specific address symbols "guides" the page what language adn direction to display.
HttpModule - The HttpModule is the filter for all requests. It receives notification at various processing points during the lifespan of the request. We can map HttpModule to all application requets.
The main difference between HttpModule to HttpHandler is that HttpModule provides class intance for all application's requests and HttpHandler provides single instance for each request. Also, HttpModule doesn't store any data about any request because it handles all the application requests, opposite to HttpHandler that can store data about a specific request (IsReuseable property, remember...?)
An important adventage of HttpModule over HttpHandler is by the initializing and maintain an application state option, since there is alive class intance all along the application lifespan. For example, you can load a data structure (like XML string for example) in the Init method and use it safely accross the apllication lifespan.
Hope I answered some questions (if you had some...)
A nice implementation example you can find in MSDN or here.