16

When we add a new item to an ASP.NET web application project in Visual Studio 2010, I have noticed two templates:

  1. ASP.NET Handler
  2. Generic Handler

What is the difference between these two and when are they used?

Eilon
  • 25,582
  • 3
  • 84
  • 102
Sravan Kumar
  • 1,447
  • 3
  • 19
  • 41

2 Answers2

20

Generic handler:

Generic Handler is a default handler which will have @webhandler directive and has .ashx extension this generic handler is not having UI but it provides response when ever any request made to this handler.

HTTP Handler:

HTTP Handler is a process which runs and continue to server request and give response based on the request handling code. This handler does not have UI and need to configured in the web.config against extensions. One of the great example of Http Handler is page handler of ASP.NET which serves .aspx pages request.

The Main difference between Generic and HTTP handler is

Generic handler has a handler which can be accessed by url with .ashx extension while http handler is required to be configured in web.config against extension in web.config.It does not have any extension.Typical example of generic handler are creating thumbnails of images and for http handler page handler which serves .aspx extension request and give response.

To know more refer this link

coder
  • 1,980
  • 3
  • 21
  • 32
  • This answer could be enhanced with answering the last part of the question a little more clearly. I don't really know the answer myself though. I think ashx looks antiquated in the browser address bar. But the ASP.NET Handler can be mapped to a more modern looking url, but is more involved to set up. I coughed that up from my current knowledge, so I'm happy to be proved wrong. – Kind Contributor Mar 09 '16 at 11:12
  • You CAN route with Generic Handler. You can create a class (just a cs file, no ashx file necessary) with IHttpHandler and then route cleanly using this answer: http://stackoverflow.com/a/3380249/887092 – Kind Contributor Mar 11 '16 at 04:16
6
  • ASP.Net Handler is the default HTTP handler for all ASP.Net pages.
  • Generic Handler is the default HTTP handler for all Web handlers that do not have a UI and that include the @ WebHandler directive.

For more information see MSDN.

Ryan Byrne
  • 850
  • 5
  • 8
  • 1
    I think that's wrong. Generic Handler is a specific endpoint (ending in ashx) not a fallback default or pipeline listener for all other requests. I also believe ASP.Net Handler is also wrong in this answer, see @coder's answer below, this is more how I understand them. – Kind Contributor Mar 09 '16 at 11:08