Skip navigation

Back Draft

 

Tap the Pipeline

Powerful and useful HttpModules are just begging to be built.

 

By Jonathan Goodyear

 

When ASP.NET was released, third-party component vendors were quick to release new and powerful server controls that enabled functionality that was not easily available before, if at all. On the other hand, very few component vendors have released products that tap into the ASP.NET pipeline. That's a shame, because the pipeline is one of the most powerful aspects of ASP.NET.

 

The major building block upon which the ASP.NET pipeline is built is the HttpModule. By implementing the IHttpModule interface, you can obtain a reference to the current HttpApplication object that is being executed when an ASP.NET page is requested. Once you have that reference, the possibilities of what you can do are endless.

 

If your creative juices haven't started flowing with ideas, let me share a few of mine with you. Like many people, my consulting practice keeps me so busy that I don't have enough time to explore a lot of the product ideas that I have. Maybe some of you can breathe some life into these HttpModule ideas, which would otherwise just gather dust in the corners of my cluttered brain.

 

URL Rewriting Engine

The canonical demo of an HttpHandler demonstrates how to Rewrite (aka "munge") URLs (http://www.15seconds.com/issue/030522.htm). The concept behind URL munging is that you can take a URL that would normally be very complex (e.g. with a long directory structure and querystring parameters) and expose it to the world via a simple URL. When a request is made for the simple URL, the URL Rewriting HttpModule intercepts it and re-directs it to the true URL. A good example of this concept is implemented by the TinyURL Web site (http://tinyurl.com).

 

Although there are several examples of how to build a URL Rewriting HttpModule on the Web, nobody seems to have packaged the concept into a commercial product. If you want URL Rewriting functionality, you have to roll it yourself. I'd like to see somebody build a flexible and robust URL Rewriting Engine that enables a rules-based approach and has a Web-based administration tool (perhaps using an HttpHandler like Trace.axd).

 

Even though there is a lot of freeware source-code out there, I think that a good URL Rewriting Engine would sell well.

 

Image Servicing

The release of ASP.NET 2.0 will bring a new Image Service that will enable a lot of dynamic image generation functionality (which you will no doubt read about in upcoming issues of asp.netPRO). ASP.NET 2.0 is still in a holding pattern, though, and there is still a lot of room out there for specialized image handlers. Say, for instance, that I run an online photography business, and I want to offer hi-res preview pictures to my customers before they make a purchase. Obviously, I would want to watermark the images, so my customers can't just download the images and print them out themselves. An ideal solution would be to plug in an HttpHandler that would monitor access to images in a particular directory. It would then inject a watermark into any images that were requested from that directory.

 

You might argue that an HttpHandler (which operates on user-configurable file extensions) could do the same thing - and you'd be right. Your choice of implementation would largely be dependent on whether you wanted or needed access to the entire HttpApplication, or merely the HttpContext of the current request. Besides watermarking, your image servicing HttpModule could handle other image operations like cropping and thumbnailing.

 

Diagnostics

Diagnostics is by far my favorite idea for an HttpModule. I have long been a student of debugging, and .NET exposes a great deal of debugging information to the developer and administrator. Although ASP.NET tracing is adequate for raw application debugging, it would be great to have a diagnostics HttpModule that I could plug into the ASP.NET pipeline of my development and staging environments to help me diagnose tricky bugs.

 

What would really be helpful is if the HttpModule could parse and analyze application exceptions that are thrown and present me with links to the .NET Framework documentation or links to community Web sites that deal with the problem I am facing. Of course, the typical stack dump information should be available as well, but as anyone who has spent some time developing ASP.NET applications will tell you, the standard exception handler page doesn't always give you much to go on.

 

The best part about a diagnostics HttpModule is that you could merely rip it out of your machine.config or web.config file before migrating it to production (I'd suggest machine.config, in order to prevent you from having to do this repeatedly).

 

These are just three ideas for powerful and useful HttpModules that are just begging to be built (or refined into more viable commercial products). The possibilities are endless. Consider this a formal request to third-party component developers to stem some of the flood of new server controls going to market (how many different charting, menu, tree, and grid controls do we really need?), and put some of their efforts into building HttpModules that developers can snap into the pipeline of their ASP.NET applications. After two years, the HttpModule market is still wide open. Throw your hat in the ring now.

 

Jonathan Goodyear is president of ASPSoft (http://www.aspsoft.com), an Internet consulting firm based in Orlando, Fla. He's a Microsoft Certified Solution Developer (MCSD) and author of Debugging ASP.NET (New Riders). Jonathan also is a contributing editor for asp.netPRO. E-mail him at mailto:[email protected] or through his angryCoder eZine at http://www.angryCoder.com.

 

 

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish