1. Original Entry + Comments2. Write a Comment3. Preview Comment
New comments for this entry are disabled.


March 14, 2005  |  HttpHandlers  |  3796 hit(s)

Bertrand LeRoy illustrates how easy (well, relatively) it is in Whidbey/Visual Studio 2005 to create HttpHandlers (.ashx files). Ease of development aside, he points out that handlers are a comparatively less-understood feature in ASP.NET. He says: "There is little documentation about them in v1, and no support for them in Visual Studio 2003." From personal experience (on both sides of the docs) I concur heartily, unfortunately, with the first point he makes.

Even in v1, though, handlers are not hugely difficult to create. The QuickStarts have a simple example that's a good start for most people.

Aside from handlers not being very well documented, I think that the virtues and purpose of handlers are not very well advertised, especially for Mort+ developers, let's call them -- folks who are a step or two beyond simple page development. Advanced developers are usually facile with them, but the existence and choice of handlers is, IMO, not well presented for people coming up to speed in ASP.NET. The best introduction I got to handlers was a presentation by Stephen Walther, who did a great demo at a user group meeting of HttpHandlers and HttpModules.

In particular, I think that ASP.NET noobies tend to be led to create .aspx pages for almost every purpose, basically because you can. You can create an RSS feed, for example, using an .aspx page, even though there is nothing in an RSS feed that constitutes a page in the ASP.NET sense. I was talking to Nikhil about this a while back. Nikhil is a design purist, and if I understand him right, he believes that you should never use an .aspx file for anything other than HTML rendering. To him it seems obvious that the way to create an RSS feed is via a handler, and in his blog[1] that's what he does for his feed. More generally: if the request endpoint renders markup, then (and only then) use an .aspx page. Otherwise, use a different endpoint, which often is a handler. Bertrand's illustation is a dynamic image, which is another great example of when to use a handler.

Here are some more resources on creating handlers:

Using HTTP Modules and Handlers to Create Pluggable ASP.NET Components

http://www.devx.com/dotnet/Article/6962/0/page/1

Using ASP.NET HTTP Handlers to create a photo album

One of these days I'll get around to implementing handlers for some of the functionality on this blog, like the aforementioned RSS feed.

[1] From which I, er, leveraged a number of design ideas when I was first creating my blog. Though not the handler-for-RSS idea. :-)

Update 3/17/05  Scott Hanselman has a
blog post that reiterates the purpose of HttpHandlers and that includes his HttpHandler boilerplate template.




Bertrand Le Roy   17 Mar 05 - 2:24 PM

The quickstarts do document how to create a httphandler, but they do not show ashx files, which is a pity as they are relatively easier (no config tweaking).
Cheers!