ASP.NET

Conclusion: Custom Handlers

ASP.NET includes a number of built-in classes to handle most kinds of requests. For example, ASP.NET includes UI handlers (System.Web.UI.Page and System.Web.UI.Control). ASP.NET also includes a Web service handler (System.Web.Services.Service). These classes will probably solve most of the requirements you might come across. However, for those fringe cases requiring custom handling, ASP.NET supports the custom handler.

The endpoint for requests coming through ASP.NET is always a class implementing IHttpHandler. IHttpHandler has very little surface area. You simply override the IsReusable property and the ProcessRequest method. ProcessRequest can pretty much do anything you want it to. The example in this tutorial included a handler that manages rendering a form and handling input.

For a custom handler assembly to work, it must be mapped to a file path or extension in the application's Web.Config file. The extension must also be mapped within the IIS metabase.

ASP.NET also supports handlers that may be compiled just-in-time. Simple handlers are easy to create and deploy because you don't need to modify the Web.Config file, nor do you need to modify the IIS metabase.

Tutorial 18 Quick Reference

How to create a custom handler assembly

  1. Create a new class implementing IHttpHandler

  2. Override the IsReusable property

  3. Override ProcessRequest


How to assign a file mapping to the handler in ASP.NET

Mention the handler in the <httpHandler> node of the application's Web.Config file


How to assign a file mapping to the handler in IIS

  1. Right-click on the virtual directory

  2. Select Properties

  3. Click the Configure button

  4. Click the Add button

  5. Add a new extension and map it to aspnet_isapi.dll


How to create a simple handler

  1. Select Web site | Add New Item

  2. Select Generic Handler from the templates

  3. Insert your own code for responding to the request

by BrainBellupdated
Advertisement: