ASHX Introduction and the difference between ashx file and aspx file _ practical Tips

Source: Internet
Author: User

What file is Ashx?

The. ashx file used to write Web handler. ashx files are similar to. aspx files, which you can use to invoke the HttpHandler class, which eliminates the process of control parsing and page processing for ordinary. aspx pages. is actually a mixed file with HTML and C #.

The. ashx file is suitable for creating data formats for browsers to handle that do not require postback processing, such as for generating dynamic pictures, dynamic text, and so on.

The ashx file is a. NET 2.0 new file type (actually available under. NET 1.0, but not publicly available).

What is the difference between a ashx file and an aspx file? Let's start with a new ashx file to see:

code example:
Of course you can use the. aspx file suffix entirely. Using. ASHX allows you to focus on programming without having to manage related web technologies ... ashx must contain isreusable. As shown in the following example

Copy Code code as follows:

<% @ webhandler language= "C #" class= "Averagehandler"%>

Using System;

Using System.Web;

public class Averagehandler:ihttphandler

{

public bool IsReusable

{get {return true;}}

public void ProcessRequest (HttpContext ctx)

{

CTx. Response.Write ("Hello");

}

}


The advantage of ASHX. aspx is that you don't need one more HTML

Look, it's a lot simpler than aspx. There is only one file, no background CS file (based on code security considerations, we will add this file ourselves). Ashx contrast aspx files, as if the CS file is missing. Actually, this is where ashx and aspx differ, Because ASPX separates front and back display and processing logic, so it turned out to be two files, in fact, in the final compilation, ASPX and CS will be compiled into the same class. Some logical processing of HTML should be designed. and ashx different, it's just a simple web The direct return of the HTTP request returns the result you want to return. The process of processing HTML less than ASPX. Theoretically, it's faster than ASPX.

Look at the configuration requested for two file types in the. net config file.

<add path= "*.aspx" verb= "*" type= "System.Web.UI.PageHandlerFactory" validate= "True"/>
<add path= "*.ashx" verb= "*" type= "System.Web.UI.SimpleHandlerFactory" validate= "True"/>

You can see two file processing classes are not the same (Ashx processing class called Simplehandlefactory, since simple, should be handled by the process is also relatively simple. Response speed should also be faster:)

As long as you specifically inherit the IHttpHandler how to deal with the problem, I find an early introduction to the. NET 2.0 compilation model. More esoteric, to slowly tinker: (Taiwanese friends to write pdf file, upload, in some places slightly.) )

When you're done, you'll probably get the ashx. NET a custom request format, the Ashx file class file is much simpler to process than ASPX.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.