An HTTP handler is a process that runs on server to response to a particular type of request. HTTP handlers can be referred to as endpoint also. A typical example of HTTP handlers is when ASP.net page handler which is used by asp.net engine to process the request that come for .aspx files.
Built In HTTP Handlers in ASP.net
|ASP.net Page Handler (*.aspx)||A default page handler for all ASP.net pages.|
|Web Service handler(*.mspx)||The default HTTP handler for Web service pages created as .asmx files in ASP.NET.|
Generic Web handler (*.ashx)
|The default HTTP handler for all Web handlers that do not have a UI and that include the @ WebHandler directive.|
Trace handler (trace.axd)
|A handler that displays current page trace information. For details, see How to: View ASP.NET Trace Information with the Trace Viewer.|
How to Create A Custom HTTP Handler
To create a custom HTTP Handler you need to implement either IHttpHandler or IHttpAsyncHandler for synchronous and asynchronous handlers. Both these interfaces expose two methods called IsReusable and ProcessRequest. ProcessRequest method is the place where you write code for handling request of your custom handler. The IsReusable property specifies whether the IHttpHandlerFactory object (the object that actually calls the appropriate handler) can put the handler in a pool and reuse it to increase performance. If the handler cannot be pooled, the factory must create a new instance of the handler every time that the handler is needed.
Public Class CustomHand Implements IHttpHandler Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable Get End Get End Property Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest End Sub End Class
Mapping File Extension in IIS
By Default IIS is going to respond to file extension that is for custom handler. If you created a new file extension for HTTP Handler then you have to explicitly register the file extension in IIS and have to add a mapping entry in web.config file for your custom handler.