Partager via


Selecting a Precompilation Model

ASP.NET provides two models for precompiling your Web site. This topic discusses the precompilation models and offers guidance on choosing the appropriate model for your Web application.

Decision Matrix

Use the following table to help you decide which compilation model to use. Each compilation model is described in more detail later in this document.

If you want to Use this compilation model

Quickly develop applications without worrying about compiling the code.

Use default compilation.

Improve the response time for the first page request to your Web site.

Use compile in place or one of the deployment compilation options.

Separate source code and user interface (UI) code.

Use compilation with updatable UI.

Modify the UI code without changing the source code.

Use compilation with updatable UI.

Remove all source code and UI code from your production server.

Use compilation with non-updatable UI.

Update your application by replacing specific assemblies.

Use compilation with fixed names.

Increase the security of your application by using strong-named assemblies.

Use compilation with signed assemblies.

Default Compilation

There is no need to perform any manual compilation of an ASP.NET application. By default, the ASP.NET runtime will compile the Web application the first time a page in the application is requested by a Web browser. If you make a change to a file in the application, the next time a page is requested the ASP.NET runtime will determine the dependencies on the changed file and recompile only the files that are affected by the change.

Advantages

The advantages of using default compilation include the following:

  • Simple to use. The ASP.NET compiler does all the work for you.

  • Best compilation model to choose during development when the extra steps required for precompiling a Web site slow down the development process.

Disadvantages

The disadvantages of using default compilation include the following:

  • Can cause significant delays when the Web site is first requested.

  • Requires you to store source-code files on the production server.

  • Makes source code and UI code available to anyone with file-system access to the Web site directory on the server.

When to Use Default Compilation

Use default compilation in the following situations:

  • When you are developing and testing a Web site.

  • For Web sites with primarily static information.

  • For Web sites that are not frequently changed.

In-Place Compilation

You can use the ASP.NET Compilation Tool (Aspnet_compiler.exe) to precompile a Web application. The compilation tool calls the ASP.NET runtime to compile the Web site in the same manner as when a user requests a page from the Web site.

If you make a change to a file in the application, you can recompile the affected file with the ASP.NET Compilation Tool, or the affected files will be recompiled the next time a page is requested from the application.

For more information about this compilation model, see How to: Precompile ASP.NET Web Sites.

Advantages

The advantages of using in-place compilation include the following:

  • First-request response time from the Web site is reduced.

  • No special deployment steps are needed; your application is compiled exactly as if a page was requested from your site.

Disadvantages

The disadvantages of using in-place compilation include the following:

  • All source code for the application must be stored on the production server.

  • Makes source code and UI code available to anyone with access to the Web site directory.

When to Use In-Place Compilation

Use in-place compilation in the following situations:

  • You make frequent changes to pages on your Web site.

  • You are not concerned about storing source-code files on your production server.

  • You want to improve the response time for first page requests.

Precompiling with Updatable UI

By using the -u switch of the ASP.NET Compilation Tool, you can compile source code (.cs and/or .vb files, and .resource files) to a DLL and leave the UI markup in the .aspx files available for updating.

After deploying the Web site to a production server, changes to the .aspx code can be made without requiring the entire Web site to be recompiled.

For more information about this compilation method, see How to: Precompile ASP.NET Web Sites for Deployment.

Advantages

The advantages of precompiling a Web site with updatable UI include the following:

  • First-request response time from the Web site is reduced.

  • User interface developers can modify the appearance and behavior of a Web site without recompiling the entire Web site.

  • Intellectual property contained in the application's source code is protected from casual observation by anyone with file-system access to the Web site directory.

Disadvantages

The disadvantages of precompiling a Web site with updatable UI include the following:

  • Requires a separate compilation step before deployment to production servers.

  • Intellectual property contained in the application's UI code (.aspx files) is available to anyone with access to the Web site directory.

  • Multiple pages cannot reference the same CodeFile class.

When to Precompile with Updateable UI

Precompile your application with updatable UI in the following situations:

  • UI designers are working separately from source-code developers.

  • Your source code contains intellectual property that you want to protect from casual observation.

  • You do not want to store source code on your production servers.

Precompiling with Non-Updatable UI

The ASP.NET Compilation Tool can compile all of the source code for an application, including UI files, such as .aspx and .ascx files, into DLLs that are deployed in the application's Bin directory.

For more information about this compilation method, see How to: Precompile ASP.NET Web Sites for Deployment.

Advantages

The advantages of precompiling with non-updatable UI include the following:

  • First-request response time from the Web site is reduced.

  • Intellectual property contained in the application's source code and UI code is protected from casual observation by anyone with access to the Web site directory.

Disadvantages

The disadvantages of precompiling with non-updatable UI include the following:

  • Requires a separate compilation step before deployment to production servers.

  • Minor changes to the application's UI require the entire Web site to be recompiled.

When to Precompile with Non-Updatable UI

Precompile your Web site with non-updatable UI in the following situations:

  • Your UI code contains intellectual property that you want to protect from casual observation.

  • You only want to have compiled DLLs on your production servers.

Precompiling to Fixed-Name Assemblies

The ASP.NET Compilation Tool uses random names for the assemblies that are generated during compilation. The name of the assembly changes each time the application is recompiled.

Because the assembly names change, you must redeploy the entire application to service one assembly. By using the ASP.NET Compilation Tool's -fixednames switch, you can create one assembly for each page in the application. The name of the assembly will not change on subsequent compilations, so you can create service releases of your application that replace only the changed assemblies.

Because using the -fixednames switch creates an individual assembly for each page, you should limit the number of pages in the application.

For more information about this precompilation method, see How to: Generate Fixed Names with the ASP.NET Compilation Tool.

Advantages

The advantages of precompiling to fixed-name assemblies include the following:

  • The name of each assembly does not change from compilation to compilation, allowing you to replace specific assemblies without redeploying the entire application.

  • Minor updates to your application can be more targeted.

Disadvantages

The disadvantages of precompiling to fixed-name assemblies include the following:

  • One assembly is created for each page in the application. This can create a large number of assemblies for sites with many pages.

When to Precompile to Fixed-Name Assemblies

Precompile your Web site to fixed-name assemblies in the following situation:

  • You need to service Web applications without replacing the entire application.

Precompiling to Signed Assemblies

You can use the ASP.NET Compilation Tool to create strong-named assemblies that can be deployed to the server's Global Assembly Cache (GAC) or to the Bin directory of the application. Using a signed assembly makes it harder for malicious users to replace your application's assemblies with malicious code.

For more information about this compilation method, see How to: Sign Assemblies for Precompiled Web Sites.

Advantages

The advantages of precompiling to signed assemblies include the following:

  • Signed assemblies increase the security of your application by making it harder for your assemblies to be replaced by malicious code.

Disadvantages

The disadvantages of precompiling to signed assemblies include the following:

When to Precompile to Signed Assemblies

Precompile your Web site to signed assemblies in the following situations:

  • Users have access to the application directory or GAC, and they can replace the application's assemblies.

  • You want to limit the ability of third parties to replace the assemblies generated by your code.

See Also

Reference

ASP.NET Compilation Tool (Aspnet_compiler.exe)

Other Resources

ASP.NET Web Site Precompilation