Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

handler

ashx

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?

like image 811
johnny Avatar asked Mar 06 '09 17:03

johnny


People also ask

What are ASHX files?

ASHX files are files used with ASP.NET programming and can be opened with any program that codes in ASP.NET, such as Microsoft Visual Studio and Microsoft Visual Community. As they are text files, you can also open ASHX files with a text editor program.

What is ASP.NET web handler?

An ASP.NET HTTP handler is the process that runs in response to a request that is made to an ASP.NET Web application. 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 handler.

What is a handler file?

A "handler" is an internal Apache representation of the action to be performed when a file is called. Generally, files have implicit handlers, based on the file type. Normally, all files are simply served by the server, but certain file types are "handled" separately.


1 Answers

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

like image 97
Mike Marshall Avatar answered Sep 21 '22 15:09

Mike Marshall