For web development, the most important thing is to generate an HTML page. Besides the stream-based output of characters and characters, is there a simple way to create a processing program to generate a webpage?
Yes! That is, no code is written. Of course, we do not write it by ourselves, which is generated by the program.
For website development, the most common function is to generate HTML webpages. Although the processing program can combine the text output stream to generate any webpage theoretically, the development efficiency is obviously not optimistic.
To fundamentally solve this major development problem, ASP. NET uses templates to generate a processing program. The template extension isAspx, Compile the aspx Template into the processing code through a built-in processing factory pagehandlerfactory, and then return the processing program to httpapplication to complete request processing. Template files in the form of aspx can be edited directly through a text editor, or even through webpage design software such as Dreamweaver, which greatly improves the efficiency of website development, it brings about a revolutionary upgrade of website development technology.
In the ASP. NET system configuration file, the following configuration has been performed. You can see that for requests with the extension of aspx, The pagehandlerfactory handler factory processes the requests. The Code is as follows:
<add path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" validate="True" />
This class is defined in the namespace system. Web. UI. The specific definition is as follows:
public class PageHandlerFactory : IHttpHandlerFactory
Relationship between the aspx template file and the page class and the generated class:
Note that the parsing and code generation of the aspx template only appear in the first processing, and later requests will directly use the compiled assembly, this process does not reduce the processing speed of the website.
For An ASPX template file, a CS background code file with the same name usually exists, and a class with the same name as the page is defined, the code file shows the class derived from the page base.
Pagehandlerfactory generates two classes through the aspx file. One is a classification with the same name as the class defined in the background code, this category combines the classes defined in the background code into a page derived from page when compiling. However, in ASP. net, the class that creates the actual page object is not this class, but the second class generated. Generally, the class name is underlined and aspx behind the Page name. This is the page class that actually creates the Page Object.
For example, we have a page file mypage. aspx, a corresponding background code file mypage should exist. aspx. CS or mypage. aspx. VB, which defines the derived class of mypage.
Through pagehandlerfactory, mypage. aspx generates two classes: mypage and mypage_aspx. The mypage in the background code file is combined with the generated partial classification mypage into a complete mypage class definition during compilation, mypage_aspx is a page class derived from mypage, used to create an actual page object instance. Shows the relationship between them:
Because the page handler is generated through the template, in most cases, we only need to create this aspx template. httpapplication will create this generated Handler through pagehandlerfactory, then use this handler to complete the server's processing tasks.
Now, if we need to generate a webpage through the processing program, we only need to design An ASPX page.
In some special circumstances, we need to create some programs that generate HTML output, but these programs do not want to be directly requested by the client, so, you can use pageparser or buildmanager to create a custom processing program to complete the processing task through An ASPX template.
[Click "Green Channel" belowFollow debuglzq", Grow together with debuglzq!]