Tutorial :What is an Handler?


Very noob question,

In asp.net can you explain in the simplest possible way "what is an handler?" How can you use handlers..

Thanks a lot.


Do you mean an "event handler", or something that inherits from IHttpHandler? In both cases handler describes something that reacts to an event occuring. An event handler would be, for example, a method that is called when a button is clicked:

public void MyButton_OnClick(object sender, EventArgs e)  {    // Code to respond to the button click here  }  

Something that inherits from IHttpHandler could be, for example, a page in an ASP.net Web Forms application (as all pages you create inherit from System.Web.UI.Page which in turn inherits from IHttpHandler) or a "Generic Handler" (a file usually with the extension .ashx).

An example of a generic handler would be:

public class MyGenericHandler : IHttpHandler  {      public void ProcessRequest(HttpContext context)      {          context.Response.Write("Hello, world!");      }        public bool IsReusable      {          get          {              return true;          }      }  }  

This would be more performant than having an ASP.net Web Forms page that did similar as it doesn't need to build all the Web Forms "framework" of the page lifecycle, viewstate and so on for each request, which means that it's better suited to requests that don't need to render presentation/markup, such as anything that would be responding to an AJAX request.


A handler is a piece of code which is called when something happens, and usually takes some action, like generating a response.

A HTTP handler is called when a HTTP request is done, and it handles the request. That is, it creates some response depending on what the request is.


ASP.NET Introduction to HTTP Handlers:



In ASP.NET Handler -> HttpHandler is anything that can process an HttpRequest and produce response in any form. All ASP.NET Pages are HttpHandlers and they produce HTML output that is sent to requesting client/browser.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »