Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an HttpHandler in ASP.NET

What is an HttpHandler in ASP.NET? Why and how is it used?

like image 335
Nikola Stjelja Avatar asked Dec 24 '08 09:12

Nikola Stjelja


People also ask

What is HTTP handler in ASP.NET MVC?

HTTPHandler is a low level request and response API in ASP.Net for injecting pre-processing logic to the pipeline based on file extensions and verbs. An HTTPhandler may be defined as an end point that is executed in response to a request and is used to handle specific requests based on extensions.

What is HTTP handler in .NET core?

The purpose of HttpHandler in standard web aplications is to handle the incoming request and process it and detect the particular resource depending on the extension. For example the request is like - http://localhost/mvc/mvc.html - here this request is asking for a resource with . html extension.

What is HTTP handler in Web API?

A message handler is a class that receives an HTTP request and returns an HTTP response. Message handlers derive from the abstract HttpMessageHandler class. Typically, a series of message handlers are chained together.


1 Answers

In the simplest terms, an ASP.NET HttpHandler is a class that implements the System.Web.IHttpHandler interface.

ASP.NET HTTPHandlers are responsible for intercepting requests made to your ASP.NET web application server. They run as processes in response to a request made to the ASP.NET Site. The most common handler is an ASP.NET page handler that processes .aspx files. When users request an .aspx file, the request is processed by the page through the page handler.

ASP.NET offers a few default HTTP handlers:

  • Page Handler (.aspx): handles Web pages
  • User Control Handler (.ascx): handles Web user control pages
  • Web Service Handler (.asmx): handles Web service pages
  • Trace Handler (trace.axd): handles trace functionality

You can create your own custom HTTP handlers that render custom output to the browser. Typical scenarios for HTTP Handlers in ASP.NET are for example

  • delivery of dynamically created images (charts for example) or resized pictures.
  • RSS feeds which emit RSS-formated XML

You implement the IHttpHandler interface to create a synchronous handler and the IHttpAsyncHandler interface to create an asynchronous handler. The interfaces require you to implement the ProcessRequest method and the IsReusable property.

The ProcessRequest method handles the actual processing for requests made, while the Boolean IsReusable property specifies whether your handler can be pooled for reuse (to increase performance) or whether a new handler is required for each request.

like image 193
splattne Avatar answered Sep 22 '22 08:09

splattne