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.