120

What are the differences between .aspx and .ashx pages? I use ashx now when I need to handle a request that was called from code and returned with a response, but I would like a more technical answer please.

0

4 Answers 4

109

Page is a special case handler.

Generic Web handler (*.ashx, extension based processor) is the default HTTP handler for all Web handlers that do not have a UI and that include the @WebHandler directive.

ASP.NET page handler (*.aspx) is the default HTTP handler for all ASP.NET pages.

Among the built-in HTTP handlers there are also Web service handler (*.asmx) and Trace handler (trace.axd)

MSDN says:

An ASP.NET HTTP handler is the process (frequently referred to as the "endpoint") that runs in response to a request 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 through the page handler.

The image below illustrates this: request pipe line

As to your second question:

Does ashx handle more connections than aspx?

Don't think so (but for sure, at least not less than).

2
  • thank you, but you didnt mention the ashx handler, what about its Request Pipe Line ?
    – Arrabi
    Mar 29, 2011 at 10:46
  • 1
    @Arrabi, HttpHandler is just a section of the request which is being executed before Page section.
    – Oleks
    Mar 29, 2011 at 11:03
88

.aspx uses a full lifecycle (Init, Load, PreRender) and can respond to button clicks etc.
An .ashx has just a single ProcessRequest method.

3
  • What is meant by 'reusable' in this context?
    – redcalx
    Feb 6, 2013 at 11:16
  • 11
    That the web server is not obligated to create a new object instance per new request. If IsReusable=true on the Handler, then the server may reuse existing handler objects to process next requests Feb 14, 2013 at 13:04
  • 2
    So it creates an instance of handler and keeps in the memory to reuse it. It never give it back to GC.
    – uzay95
    Jan 24, 2017 at 13:02
29

.aspx is a rendered page. If you need a view, use an .aspx page. If all you need is backend functionality but will be staying on the same view, use an .ashx page.

1
  • that I know, I wanted more technical answer maybe with numbers, does ashx handle more connection than aspx ?
    – Arrabi
    Mar 29, 2011 at 8:26
3

For folks that have programmed in nodeJs before, particularly using expressJS. I think of .ashx as a middleware that calls the next function. While .aspx will be the controller that actually responds to the request either around res.redirect, res.send or whatever.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.