What are the benefits of an ASHX handler file in asp.net?

johnny picture johnny · Mar 6, 2009 · Viewed 19.1k times · Source

What are the benefits of using an ashx, or handler? Also, do I need them if I use MVC (and why not)?

Does the framework matter (2.0+)?

Why would I want to use a handler? I was recently recommended to use one for retrieving an image but I don't know why.

Thank you for your time.

Edit - is a handler faster?

Answer

Mike Marshall picture Mike Marshall · Mar 6, 2009

Just a few examples:

  1. Dynamic image generation: You can write handlers that return data driven images by creating an ASHX handler that returns image data and then using that URL in your tags. e.g. <img alt="user's custom icon" src="Icon.ashx?username=bob"></img>

  2. Returning REST-based XML or JSON data to AJAX code on the client.

  3. Custom HTML: Return totally custom HTML for a page when the ASP.NET Web Forms or MVC framework is too restrictive

I believe this has been available since 1.0