Roll Your Own HttpHandler
page 1 of 7
Published: 14 Jul 2008
Abstract
HttpHandlers are powerful tools of ASP.NET; they are used fairly often, and give great power to developers using them. In this article, Brendan describes the basics of how to use these tools. He describes in easy to understand terms how one can implement the IHttpHandler class, and illustrates his explanation using code snippets and screen shots.
by Brendan Enrick
Feedback
Average Rating: 
Views (Total / Last 10 Days): 32447/ 95

Introduction

One of the more interesting pieces of ASP.NET is the concept of HttpHandlers. Sadly, this article does not delve much into what handlers are or for what they are used. Instead, this article just gives a quick introduction for you to be able to write your own HttpHandler. The text following explains how to create a simple HttpHandler, and a few of the design decisions you will have to make when creating your own. You can download the sample project for this article here or at the bottom of the article.

There are plenty of ways in which one can benefit from the use of HttpHandlers. They are very versatile. They can be applied to a lot of different tasks. Keep in mind there are also HttpModules which are also extremely useful tools, but they are a bit different from HttpHandlers. I will not be delving into that topic in this article. Please read elsewhere to learn more about the differences between HttpHandlers and HttpModules.

I know plenty of people who have configured IIS to send all requests for gifs, pngs, jpgs, etc. to ASP.NET HttpHandlers so that site owners can clamp down on hotlinking, leeching, or whatever you want to call it. It is where someone else links to your sites content. It uses your bandwidth and you do not even get the traffic, and usually it does not mention where the content came from.

Other people will configure IIS to handle zip files so that an HttpHandler can step in and execute code every time someone wants to download a file from a site. This is much easier than some of the scripted downloads, and certainly gives great server-side control over the download - counting the number of downloads and storing in a database or whatever you want to do.

One other use of HttpHandlers, which I plan to write about soon, is to use them to watermark your images. If you have configured an HttpHandler to prevent people from leeching your images you might also use a handler to watermark your images with a copyright. This makes it less likely that people will simply save your images and display them on their own pages. Plenty of people and companies are quite concerned about this. Keep in mind that if you publish something on the internet it can never be completely safe, but you can at least discourage people.


View Entire Article

User Comments

Title: Roll Your Own HttpHandler   
Name: namyaf
Date: 7/31/2009 1:47:12 PM
Comment:
This is the second article that I read by you, and both are explained very well without assuming too much from the reader. Great job and I look forward to more of your articles! peace yo!
Title: Roll Your Own HttpHandler   
Name: Ryan A
Date: 7/16/2008 9:49:57 AM
Comment:
Good article with quick, easy to follow examples. Thanks for sharing.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2014 ASPAlliance.com  |  Page Processed at 7/25/2014 7:02:50 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search