Previous Page
Next Page

IHttpHandler

Here it is. Shield your eyes while you look at Listing 18-2.

Listing 18-2
   public interface IHttpHandler
  {
    void ProcessRequest(HttpContext ctx);
    bool IsReusable {get;}
  }

There's really not much to it, is there? The interface includes a method named ProcessRequest and a property named IsReusable. If the handler instance can be used multiple times, then IsReusable should return true. The heart of the handler is the ProcessRequest method that includes a single parameter: the current HttpContext.

Once a request finally arrives at the handler (through the ProcessRequest method), ProcessRequest can literally do anything to respond to the request. The Trace.axd handler responds to a GET request by listing the requests being tracked by the runtime. The forbidden handler responds by throwing up a roadblock so the client can't see the source. A custom Web service might respond to the request by parsing the XML payload, constructing a call stack, and making a call to an internal method.

The following example illustrates how to handle forms processing in a custom handler.


Previous Page
Next Page