Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are .ashx files in an ASP.NET application?

Tags:

asp.net

ashx

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?

like image 490
Sree Avatar asked Apr 22 '11 18:04

Sree


People also ask

What is a .ashx file?

An ASHX file is a webpage that is part of an ASP.NET web server application. It contains references to other pages hosted on the web server that are sent to the user's web browser. ASHX files are processed by the server's ASP.NET HTTP Handler when a client web browser requests the page.

What program can open a ASHX file?

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.

How do I make an ASHX file?

Go to the Website menu and click on the first menu item there, "Add New Item". This will present the Add New Item dialog box. Then Select the "Generic Handler" item, and you will get a new file with some code in it called Handler. ashx.

Are ASHX files compiled?

The ASHX will then just be a one line reference. Yes, it'll be compiled into the DLL.


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.

like image 165
Larry Avatar answered Sep 23 '22 01:09

Larry


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.

like image 40
Tom Gullen Avatar answered Sep 23 '22 01:09

Tom Gullen