When do you use ashx files in asp.net web application ? Can some one explain in simple terminology with a pratical example ? I understood from the msdn that .ashx files implements ihttphandler but i could not get much explanation from here http://msdn.microsoft.com/en-us/library/system.web.ihttphandler.aspx, Can some one explain it clearly for me?
-
1http://msdn.microsoft.com/en-us/library/Bb398986%28v=VS.100%29.aspx – Oded Apr 22 '11 at 18:42
-
1ps - nah, thats a good, clear question. how about i upvote instead :D – Nick Rolando Apr 22 '11 at 18:43
-
@Oded Do u think it is a good idea to implement a .ashx file for downloading a file from the web application when user clicks on a button rather than implementing a method to do the same? – Sreedhar Danturthi Apr 22 '11 at 18:51
-
1If all you are doing is return a file, `Response.WriteFile` is more than enough. – Oded Apr 22 '11 at 18:53
-
2it is a good question, I even up-voted – GibboK Oct 15 '11 at 09:12
2 Answers
In short, a file ASHX is an ASPX file, minus all plumbing ASP.NET webform.
I am using ASHX to generate PDF files on the fly, and download them. Similarly, I use them to generate thumbnails on the fly and download them.
This could work very well with a blank ASPX, but ASHX files are much less resource-consuming.
Take a look at this tutorial to see how the files ashx.

- 2,222
- 21
- 34

- 17,605
- 9
- 77
- 106
-
-
1Not directly. I use the .NET reporting features to render a PDF in a byte array, then I send it through the Response object. – Larry May 18 '14 at 12:34
One use I use them for is to use it to handle AJAX requests, and print the output in plaintext format. There is no need to render any HTML controls etc, just plain text/XML etc, and ASHX seems best for that.
Here is a good overview:
http://www.dotnetperls.com/ashx
You want to create an ASP.NET file that is not a typical web forms page. Your file will need to dynamically return an image from a query string, or XML and other non-HTML web pages.

- 61,249
- 84
- 283
- 456