Now we have a handler which should be working correctly. To
test this out we should run our web application project and then navigate to
anything followed by .hello, and then our handler should take over execution
and handle the request.
Here is what it looks like when our example SimpleHandler is
used to handle a request.
Figure 4: Viewing the Handler
A fairly simple way to handle this, but it works quite well.
The final code in this example can be downloaded from the
following link. I will also include the few lines of the SimpleHandler class
here.
Listing 6: Final SimpleHandler
using System.Web;
namespace RollYourOwnHttpHandler
{
public class SimpleHandler : IHttpHandler
{
public SimpleHandler()
{
}
#region IHttpHandler Members
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.Write("<html><head><title>Hi there!</title></head>" +
"<body>Hello world!</body></html>");
}
#endregion
}
}