Chapter 17. HTTP Handlers

Introduction

An HTTP handler is a class that intercepts and handles requests for a resource of a given type on a web server. HTTP handlers are a key feature of ASP.NET. For instance, when you request an .aspx file, a built-in HTTP handler intercepts the request and takes charge of loading and executing the .aspx file. ASP.NET also provides built-in HTTP handlers for .asmx, .ascx, .cs, and .vb files, as well as other file types. The <httpHandlers> element of the machine.config file contains a list of the standard HTTP handlers configured for your web server.

It’s possible to extend the built-in handlers provided by ASP.NET or to write your own. A custom HTTP handler is useful when you want to handle requests by your application for a given resource on your own. For example, custom handlers are useful for returning binary data, such as the contents of an image file, or for handling the processing necessary to access a resource stored in a database. HTTP handlers also provide a good mechanism for building reusable assemblies for your web applications, such as a general purpose file download module able to handle requests for virtually any file type. Each of these ideas is illustrated in the recipes in this chapter.

Get ASP.NET Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.