ASHX Introduction and the difference between ashx file and aspx file

Source: Internet
Author: User
Tags http request

  This article mainly describes the differences between ASHX and ashx files and aspx files. Need friends can come to the reference, I hope to help you.

What file is Ashx?  . ashx files are used to write Web handler. ashx files that 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 generating data formats for browser processing 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:   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. The following example shows the       code as follows: <% @ webhandler language= "C #" class= "Averagehandler"%>    using System   ;    Using system.web;    public class averagehandler:ihttphandler    {    public bool isreusable    {get {true;}}     public void ProcessRequest (HttpContext ctx)     {    CTX. Response.Write ("Hello");   }   }     . aspx's advantage is that you don't need an extra HTML   to see more 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.   See the configuration of two file type requests 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"/> & nbsp 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 quick:)   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 processing process is much simpler 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.