Roll Your Own HttpHandler
page 5 of 7
by Brendan Enrick
Feedback
Average Rating: 
Views (Total / Last 10 Days): 34832/ 62

The HttpHandler

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
    }
}

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-29 4:49:38 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search