Sideway from Sideway
Draft for Information Only


ASP.NET Web Site Precompilation Overview
 Precompilation Options
 In-Place Precompilation
 Precompilation for Deployment
  Precompiling for Deployment Only
  Precompiling for Deployment and Update
 Precompiling Child Applications
 Performing Precompilation
 See Also
 Sources and References

ASP.NET Web Site Precompilation Overview

By default, ASP.NET Web pages and code files are compiled dynamically when users first request a resource such as a page from the Web site. After pages and code files have been compiled the first time, the compiled resources are cached, so that subsequent requests to the same page are extremely efficient.

ASP.NET can also precompile an entire site before it is made available to users. This provides a number of advantages, including:

  • Faster response time for users, since pages and code files do not have to be compiled the first time they are requested. This is particularly useful on large sites that are updated frequently.

  • A means to identify compile-time bugs before users see a site.

  • The ability to create a compiled version of the site that can be deployed to a production server without source code.

Precompilation Options

ASP.NET offers two options for precompiling a site:

  • Precompiling a site in place. This option is useful for existing sites where you want to enhance performance and perform error checking.

  • Precompiling a site for deployment. This option creates a special output that you can deploy to a production server.

Additionally, you can precompile a site to make it read-only or updatable. The following sections provide more details about each option.

In-Place Precompilation

You can enhance the performance of your Web site somewhat by precompiling it. This is particularly true in sites where there are frequent changes and additions among ASP.NET Web pages and code files—in a fluid Web site, the extra time required to dynamically compile new and changed pages can affect the users' perception of the site's quality.


Precompiling a site in place effectively performs the same compilation that occurs when users request pages from your site. Therefore, the primary performance improvement is that pages do not have to be compiled for the first request.

When you perform in-place precompilation, all ASP.NET file types are compiled. (HTML files, graphics, and other non-ASP.NET static files are left as is.) The precompilation process follows the same logic that ASP.NET uses for dynamic compilation, accounting for dependencies between files. During precompilation, the compiler creates assemblies for all executable output and places them in a special folder under the %SystemRoot%\Microsoft.NET\Framework\version\Temporary ASP.NET Files folder. Thereafter, ASP.NET fulfills requests for pages from the assemblies in this folder.

If you precompile the site again, only new or changed files are compiled (or those with dependencies on new or changed files). Because of this compiler optimization, it is practical to compile the site after even minor updates.

Precompilation for Deployment

Another use for precompiling a site is to produce an executable version of the site that can be deployed to a production server. Precompiling for deployment creates output in the form of a layout that contains assemblies, configuration information, information about the site's folders, and static files (such as HTML files and graphics).

After compiling the site, you can deploy the layout to a production server using tools such as the Windows XCopy command, FTP, Windows installation, and so on. Once the layout is deployed, it functions as the site, and ASP.NET fulfills requests for pages from the assemblies in the layout.

Precompiling a site for deployment provides a measure of protection for your source code and other intellectual property. For more information about how the compiler works with files during compilation for deployment, see File Handling During Site Compilation for Deployment.

You can precompile for deployment in two ways: precompiling for deployment only, or precompiling for deployment and update.

Precompiling for Deployment Only

When you precompile for deployment only, the compiler produces assemblies from virtually all ASP.NET source files that are normally compiled at run time. This includes program code in pages, .cs and .vb class files, other code files, and resource files. The compiler removes all source and markup from the output. In the resulting layout, compiled files are generated for each of the .aspx files (with the extension .compiled) that contain pointers to the appropriate assembly for that page.

To change the Web site, including the layout of pages, you must change the original files, recompile the site, and redeploy the layout. The only exception is the site configuration; you may make changes to the Web.config file on the production server without having to recompile the site.

This option provides the greatest degree of protection for your pages and the best performance at startup.

Precompiling for Deployment and Update

When you precompile for deployment and update, the compiler produces assemblies from all source code (except page code in single-file pages) and from other files that normally produce assemblies, such as resource files. The compiler converts .aspx files into single files that use the compiled code-behind model and copies them to the layout.

This option enables you to make limited changes to the ASP.NET Web pages in your site after compiling them. For example, you can change the arrangement of controls, colors, fonts, and other appearance aspects of pages. You can also add controls, as long as they do not require event handlers or other code.

When the site runs the first time, ASP.NET performs further compilation in order to create output from the markup.


A precompiled updatable site does not allow multiple pages to reference the same CodeFile class.

Precompiling Child Applications

Precompiling a Web site compiles only that site, not any child sites. If a Web site contains a child folder that is marked as an application in IIS, the child application is not compiled when you precompile the parent folder.

Performing Precompilation

You can precompile a Web site using the Aspnet_compiler.exe tool on the command line. For more information, see How to: Precompile ASP.NET Web Sites for Deployment and ASP.NET Compilation Tool (Aspnet_compiler.exe).

Some visual designers such as Visual Studio include commands to precompile a Web site from within the IDE. For more information, see How to: Publish and Sign Assemblies for Precompiled Web Sites in Visual Web Developer and How to: Publish and Generate Fixed Assembly Names in Visual Web Developer and How to: Publish Web Sites (Visual Studio) and How to: Publish and Sign Assemblies for Precompiled Web Sites in Visual Web Developer and How to: Publish and Generate Fixed Assembly Names in Visual Web Developer and How to: Publish and Sign Assemblies for Precompiled Web Sites in Visual Web Developer and How to: Publish and Generate Fixed Assembly Names in Visual Web Developer and How to: Publish Web Sites and How to: Publish Web Sites.

One coding restriction applies in sites that you intend to compile with source protection enabled. It is possible for a base page class (a code-behind class) to reference the associated page class (.aspx file) and page class members using a fully qualified class name. However, this type of reference will not work when precompiling your site with source protection enabled. This is because the base page class from the code-behind file is not located in the same assembly as the page class derived from the .aspx page. For more information on precompilation with source protection enabled, see How to: Sign Assemblies for Precompiled Web Sites.

See Also


How to: Precompile ASP.NET Web Sites for Deployment


File Handling During ASP.NET Precompilation

Sources and References


ID: 211100024 Last Updated: 11/24/2021 Revision: 0 Ref:



  1. Active Server Pages,  ,
  2. ASP Overview,  ,
  3. ASP Best Practices,  ,
  4. ASP Built-in Objects,  ,
  5. Response Object,  ,
  6. Request Object,  ,
  7. Server Object (IIS),  ,
  8. Application Object (IIS),  ,
  9. Session Object (IIS),  ,
  10. ASPError Object,  ,
  11. ObjectContext Object (IIS),  ,
  12. Debugging Global.asa Files,  ,
  13. How to: Debug Global.asa files,  ,
  14. Calling COM Components from ASP Pages,  ,
  15. IIS ASP Scripting Reference,  ,
  16. ASP Keywords,  ,
  17. Creating Simple ASP Pages,  ,
  18. Including Files in ASP Applications,  ,
  19. ASP Overview,  ,
  20. FileSystemObject Object,  ,
  21.,  , ADO Object Model
  22. ADO Fundamentals,  ,

Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna

Home 5






Hobbies 8


Chinese 1097

English 339

Reference 79


Hardware 224


Application 213

Digitization 32

Latex 52

Manim 204

KB 1

Numeric 19


Web 289

Unicode 504


CSS 65

SVG 46


OS 429

DeskTop 7

Python 72



Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 33

Coordinate Geometry 2

Calculus 67

Complex Analysis 21


Tables 8


Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5


Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1

Copyright © 2000-2022 Sideway . All rights reserved Disclaimers last modified on 06 September 2019