O'Reilly logo

Leveraging httpHandlers to Stream Custom Content in ASP.NET by Chris Love

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Leveraging httpHandlers to Stream Custom Content in ASP.NET

All requests in the ASP.NET pipeline are ultimately processed by an httpHandler. Each handler has a specific job to produce content to the browser, based on the request type and any parameters passed to the server. There are several built-in httpHandlers in the ASP.NET framework. For example, the System.Web.UI.Page class implements the httpHandler interface. The Page class processes all requests with the .aspx extension and produces the appropriate HTML markup to the browser.

All custom ASP.NET Handlers implement the IhttpHandler interface. This interface defines a method, ProcessRequest, and a property, IsReusable, that must be implemented by any custom handler. The IsReusable property returns either true or false, indicating if the handler can be used simultaneously or not. The ProcessRequest method is called by the .NET engine, passing a reference to the current request’s HttpContext. This is where any custom processing is done.

The IsReusable property indicates to the run time if a handler can be reused by another request. Typically this should return false, and the instance of the handler will not be pooled. Generally, for any handler that generates dynamic content, the IsReusable property should return false. If the handler returns the same content or is asynchronous, it can return true.

Custom handlers can be associated with specific file extensions or called directly as a URL. The .NET framework allows us to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required