HttpHandlers, HttpModules, Servlets & Filters

I’m in project limbo today, coming off a large ecommerce initiative for FootJoy that uses ASP, C#, Flash and Flash Remoting and moving onto another ecommerce site, this one completely C#.

I’m slowly grokking the .NET packages, I trying to understand the low-level System.Web classes today. I was interested to read about the IHttpHandler interface, which you use to create services that are similar in nature to the Java Servlet interface. Similarities I can see/find:

  • JSP’s are compiled down to servlets at runtime, .NET uses the System.Web.UI.PageHandlerFactory class when handling requests for .aspx files. Don’t believe me? Check the <httpHandlers> element of your machine.config file.
  • Servlets can be configured to respond to a variety endpoints through the <servlet-mapping> element of web.xml, HttpHandlers are added to web.config like this:

    <httpHandlers>
       <add verb=”*” path=”/mypath/somepage.aspx” type=”com.mindseye.handlers.TestHandler, TestHandler” />
    </httpHandlers>

  • Both servlets and httphandlers give you a means of interacting with the low-level request and response services of the web server

In much the same way, HttpModules and the javax.servlet.Filter class perform similar functions. An HttpModule class registers itself to listen for events that are fired in your HttpApplication (for instance the ‘BeginRequest’ event) and then can perform actions based on the occurrence of those events. A Filter is a bit different in that it is mapped to the a specific url pattern in web.xml and is then called when a request is made that matches that pattern. Just like the HttpModule class, it too can then modify the request coming in or the response going back out.

In general, I’m very impressed by ASP.NET (and thus the .NET framework).

Leave a Reply

Your email address will not be published. Required fields are marked *