Dynamic compilation in ASP. NET

Source: Internet
Author: User

1. Why is pre-compilation required?

ASP. NET 2.0 compilation methods can be divided into two types: dynamic compilation and pre-compilation. To answer why pre-compilation is required, Let's first look at what is bad about dynamic compilation. Let's review ASP. NET: When An aspx-based Http request from Brower arrives at the Web server, the IIS handle request, by analyzing the Application Mapping registered in IIS, send the Request to aspnet_isapi.dll ISAPI extension. ISAPI extension enters Http Runtime Pipeline through HttpRuntime. HttpRuntime creates a separate HttpContext object for each Request to save the Context information of the request. In Http Runtime Pipeline, Http requests are processed by a series of registered Http modules, such as the OutputCache module, Session Module, Authentication Module, Authorization, and ErrorHandler Module. On the Pipeline terminal, ASP. NET needs to create a corresponding HttpHandler object based on the request to process the Request and generate the Response to the Client. For an Http request based on Aspx, the corresponding Http handler object is generally a System. Web. UI. Page Object.

ASP. NET first checks whether the corresponding Page type exists in the cached Assembly. If yes, create a Page object directly. Otherwise, ASP. NET will first compile the Source code (including code behind, html, and so on) related to the Page. We also said that this compilation is in the unit of Directory, that is, files to be compiled under the same Directory will be compiled into the same Assembly. The compiled Assembly will be cached for subsequent requests.

It is precisely because the first access to resources will lead to a compilation that is not accurate, because dynamic compilation is performed in directory units and should be performed for the first access to resources under a Directory ), this will seriously reduce the response speed of the Web Application. To avoid this situation, we need to compile the web site in advance. Therefore, improving the web site response is the most important reason for pre-compilation.

At the same time, dynamic compilation assumes that the Source code is placed on the Web server, and they can be modified. For a developed Web Application, we prefer to deploy Binary Assembly. In this way, Binary Assembly is deployed on the Server, and the system will crash due to tampering, intellectual property rights are also more conducive to protecting trade secrets. This is another reason why we need to pre-compile.

Next we will talk about how to pre-compile and the principles behind the compilation. At the same time, I need to put forward some terms and principles mentioned in the previous section, such as Preservation file and FastObjectFactory, which are also applicable to pre-compilation and repeated content, you do not need to introduce it here. At the same time, I will keep the previous Sample. If you want to see the relevant content, see [original] in-depth analysis of one of ASP. NET Compilation principles: dynamic Compilation of Dynamical Compilation ).

2. In Place Pre-compilation V. S. Pre-compilation for Deployment

Pre-compilation can be divided into In Place Pre-compilation and Pre-compilation for Deployment. In Place Pre-compilation is very simple, in fact, it is to compile the entire Web site to a temporary directory, which is the temporary directory we are introducing dynamic compilation. This compilation method, including the generated files, is exactly the same as dynamic compilation. The only difference is the Compilation Time: Pre-compilation, and the compilation scope: the entire Web site. This compilation method is commonly used in VS build. This compilation method is generally used in the development phase.

Compilation for Deployment is the focus of our discussion today. Next we will discuss Pre-compilation for Deployment.

Note: In ASP. NET is compiled by a tool called aspnet_compiler. NET 2.0 is released together. You can use this tool to execute compilation in command line mode, and set different compilation options by passing different command line switches. This tool is placed in VS so that you can use VS for visual compilation.

3. Non-updatable Pre-compilation V. S. Updatable Pre-compilation

ASP. NET 2.0 provides several methods for pre-compilation and deployment. To find out the pre-compilation and deployment methods, let's review the compilation methods under ASP. NET 1. x. We know that in ASP. NET 1. in the era of x, we compile the entire Web site. In fact, we only need to compile all C # and VB. NET and other background code, and generate a single Assembly. The aspx of Web page does not participate in compilation. So when we access a Web page, ASP. NET must dynamically compile aspx.

 
 
  1. <%@PageLanguage="C#"AutoEventWireup="false"  
  2. Codebehind="Default.aspx.cs" 
  3. Inherits="Default"%> 
  4. publicpartialclassDefault:System.Web.UI.Page  
  5. {  
  6. protectedvoidPage_Load(objectsender,EventArgse)  
  7. {  
  8. }  
  1. Microsoft released multiple function updates for ASP. net mvc 2 preview Edition
  2. ASP. NET Server custom control security guidelines
  3. Analysis of ASP. NET programming standards and Their encoding specifications
  4. Introduction to ASP. NET sessions
  5. ASP. NET programming tool ASP. NET Web Matrix

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.