Changes in page compilation model in ASP. NET 2.0 beta2

Source: Internet
Author: User

Sun zhanbo's blog already describes the adjustments made by beta2 against beta1 for special directories. In addition, the beta2 compilation model will also make a considerable modification to beta1.

First, return to the "Ancient Times" of ASP. NET 1.1 to see how the ASP. net engine processes page files and code-behind files.

We usually see the following statement above the page file:

<% @ Page codebehind = "default. aspx. cs" inherits = "webapplication1.cdefault" %>

When we add a new ASP. NET control to the page file, vs. NET will automaticallyCodeAdd a protecte object declaration in the file, and use and operate the object in the code. Vs. Net always maintains the synchronization between the controls in the page file and the control object declarations in the code file.

When we compile the site, vs. Net compiles all code-behind files together to generate a. dll file in the/bin directory. Then, we deploy all the page files and/bin on the server. ASP. the net engine automatically generates. CS class file, and according to the content specified by "inherits" in the header Declaration of the page file, let this class inherit from the specified parent class. In this way, the page is combined with the content in the background code file by "inheritance.

The biggest problem with this page compilation model is that the controls in the page must be synchronized with the control object declaration in code-behind at all times. Although developers do not realize this, if. if the synchronization fails due to an error in net, the connection through "inheritance" will be damaged.

OK. In ASP. NET 2.0 beta1, we can finally achieve the separation and connection between the page file and the code-behind file in a more elegant way. With the new language feature of partial class, we can finally get rid of clever, but clumsy inherited connections. To reflect the features of the background code file in beta1, we simply call the background code file code-beside.

At the top of the page file, a statement is made as shown below:

<% @ Page Language = "C #" compilewith = "default. aspx. cs" classname = "default_aspx" %>

Note that vs. Net does not provide us with a means to compile all the code-Beside files into A. dll in/bin.

During deployment, we directly copy all the page files and code-Beside files to the server. When a user browses a page, the ASP. net engine automatically generates a partial Class Based on the content on the page, and then integrates it with the partial class in code-Beside to complete the compilation. This compilation process (page file and code-Beside) is completely completed dynamically at runtime. If we modify the page file or code-Beside file, no manual operation is required, ASP. net engine will automatically re-compile the next time you browse.

Well, of course, many people may feel uncomfortable. "Why should I deploy the background code file ?" Therefore, Asp. net beta1 also provides other compilation and deployment solutions, such as compiling all the content of the entire site, including the page file and the code-Beside file, into one. DLL, and then deploy it on the server.

Finally, let's take a look at the changes in the page compilation model in ASP. NET beta2.

The Declaration at the top of the page file is as follows:

<% @ Page codefile = "default. aspx. cs" inherits = "default_aspx" %>

How is it? Seeing "inherits", do you doubt that you are going back to ASP. NET 1.1? Yes, no.

When. when creating a page. net will automatically create a code-behind (we will re-use the word code-behind) file, when we add a control on the page,. net, like beta1, does not add a declaration in code-behind. However, when we compile the site,. net automatically generates a "temporary intermediate" partial class based on the content of the page file, and then compiles the partial class and the partial class in code-behind to generate. DLL file.

During deployment, we deploy/bin and all page files on the server just like ASP. NET 1.1. ASP. net engine generates a class file based on the page content, and then according to the "inherits" value declared in the file header, let this class file inherit from the specified parent class, and finally complete the compilation process.

In short, the page compilation model of beta2 absorbs ASP. NET 1.1 and ASP. NET 2.0 beta1 advantages. We can compile all the background code of the site, deploy it together with all the page files, and obtain beta1, during development, there is no need to declare the benefits of page control objects in the background code file.

Of course, for developers, all these operations are under the "lid". We don't need to know this, so we can easily develop them.

Microsoft will launch a newCommunityThe technical Preview (CTP) will reflect all these changes. Beta2 is expected to be released early next year, and its design will basically continue to RTM.

For more details, refer to this article on msdn.

Related Article

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.