Roll Your Own HttpHandler
page 2 of 7
by Brendan Enrick
Feedback
Average Rating: 
Views (Total / Last 10 Days): 34821/ 49

Setting up the Solution

Start by getting yourself a solution to work with. You will want to have 2 projects in the solution. One needs to be some form of a web application, either your production application or just one with which to test. You will also want to have a Library. This DLL built by the library will be the HttpHandler. The website will be configured to send certain requests to be handled by the handler in that assembly.

Once you have created your solution you should have a solution explorer that looks a little bit like mine. As a note, keep in mind that I am using a web application project and not a web site. You can use a web site if you want. I prefer web application projects, but web sites work perfectly well also.

Figure 1: Solution Explorer Initial Setup

It is important to make sure that we tie these two applications together. We will use a project reference here so that we can have the assembly of our handler build and be added into the web application so it can use it. To do this just click on the reference folder in your project and select add a reference. This will probably take some time to load the first time you run it.

Figure 2: Adding Project Reference

Before you can actually turn the class library into a handler, there is one assembly you will need to include for it. This assembly is the System.Web assembly. This is the one which contains the information about dealing with the web. Handlers are obviously web related, so we will add that assembly to our class library project. Do this just like before, right clicking on the references folder and choosing to add a reference. This will probably be faster than the first time, so once it loads you can just find the correct assembly in the list.

Figure 3: Adding a System.Web Reference

Once you have added the System.Web reference you will be able to use the IHttpHandler interface, which is really all that is needed in order to create a handler. Any class that implements that interface is able to be a handler. The interface only has two methods which must be implemented. There are the IsReusable property and the ProcessRequest method.


View Entire Article

User Comments

Title: Roll Your Own HttpHandler   
Name: namyaf
Date: 2009-07-31 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: 2008-07-16 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-2024 ASPAlliance.com  |  Page Processed at 2024-03-28 2:10:14 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search