Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction to ashx and what are the differences between ashx files and aspx files

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "the introduction of ashx and the difference between ashx file and aspx file". In daily operation, I believe many people have doubts about the introduction of ashx and the difference between ashx file and aspx file. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "ashx introduction and the difference between ashx file and aspx file". Next, please follow the editor to study!

What kind of file is ashx?

The .ashx file is used to write web handler. The .ashx file is similar to the .aspx file, which allows you to call the HttpHandler class, eliminating the need for normal .aspx page control parsing and page processing. It's actually a mixed file with HTML and C#.

.ashx files are suitable for producing data formats that are processed by browsers and do not require postback processing, such as for generating dynamic pictures, dynamic text, and so on.

Ashx files are new file types in .net 2.0 (actually available under .net 1.0, but not publicly available).

What is the difference between an ashx file and an aspx file? Let's first create a new ashx file and have a look:

Code example:

Of course, you can use the .aspx file suffix. Using .ashx allows you to focus on programming regardless of the related WEB technologies. .ashx must contain IsReusable. As shown in the following example

The copy code is as follows:

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 over .aspx is that you don't need one more html.

Look, it's much simpler than aspx. There is only one file, no background cs file (for code security reasons, we will add this file later). Ashx compares aspx files, just like missing cs files. In fact, this is the difference between ashx and aspx, because aspx needs to separate the foreground and background display and processing logic, so it is made into two files. In fact, in the final compilation time, aspx and cs will still be compiled into the same class. It is necessary to design some logical processing of html. Unlike ashx, it simply returns the result you want to return directly to the web http request. Less html processes are handled than aspx. In theory, it is faster than aspx.

Take a look at the configuration of requests for two file types in the. Net config file

You can see that the classes handled by the two files are different (the class handled by ashx is called SimpleHandleFactory, and since it is called Simple, the process should also compare Simple. The response speed should also be faster:)

As long as I specifically inherit the problem of how IHttpHandler handles it, I find an early article that introduces the .net 2.0 compilation model. It's more esoteric, so you should slowly tinker with it: (the Pdf file written by a friend in Taiwan can't be uploaded, so I'll outline it in some places.)

After tinkering, you will probably understand that ashx, but a custom request format in. Net, the processing of files in the ashx file class is much easier than aspx.

At this point, the study on "the introduction of ashx and the differences between ashx files and aspx files" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report