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

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

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 1 and 5 and type the answer here:

User Comments

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.

Product Spotlight
Product Spotlight 
Learn More
.NET Tools
asp.net shopping cart
asp.net chart control






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


©Copyright 1998-2008 ASPAlliance.com  |  Page Processed at 12/2/2008 9:08:41 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search