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.

Overriding ASP.NET's Built-in HTTP Handlers

The <httpHandlers> element in machine.config defines how ASP.NET handles requests for all of the standard file extensions found in most ASP.NET applications. These include . aspx , . asmx , . ascx , . cs , . vb , . vbproj , . csproj , . soap , and many others. By placing your own handler settings in web.config , you can override those defined in machine.config . The override maps incoming requests to the appropriate IHttpHandler class you define (see Recipe 17.1s Recipe 17.1.3 for more details). The override can be for a single URL or for all requests with a given extension.


HTTP handlers are similar to the ISAPI extensions used to implement classic ASP for IIS. But, whereas ISAPI extensions are difficult to implement and can only be implemented in C++, HTTP handlers are supported by ASP.NET and can be implemented in any .NET language.



ASP. NET Cookbook
ASP.Net 2.0 Cookbook (Cookbooks (OReilly))
ISBN: 0596100647
EAN: 2147483647
Year: 2006
Pages: 179

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net