Precompilation


Usually an ASP.NET page, including all dependent source code files, is automatically compiled on the first request. This once-compiled version is used until the page or one of its dependencies changes. Besides this approach, version 2.0 offers precompilation. In this approach, all the pages and all related files are compiled explicitly and at once.

There are two different kinds of precompiling: in-place precompilation and precompilation for deployment. The following sections describe these precompilation types in detail.

In-Place Precompilation

You execute in-place precompilation by calling the following URL: ://precompile.axd">http://<Host>:<Port>/<App>/precompile.axd. Direct integration of this functionality in VS .NET is being planned. So far, so good, but what is it worth? It has two advantages:

  • The first request of each page gets accelerated because it's completely compiled already. From the second request on, there's no gain in speed.

  • You can detect and fix all compilation errors at once.

Precompilation does more for you than previous versions of VS .NET did. The ASPX files are converted to classes and stored as DLLs in the cache directory together with any code-beside. Only static pages and (graphic) resources are taken out of the directory of the web site afterward.

Note

After the first in-place precompilation, any changes are included incrementally. This kind of compilation makes sense even if there are only small changes.

Precompilation for Deployment

The other type of precompilation is targeted for a different purpose. It allows you to distribute an entire compiled web site compiled as DLLs. In contrast to previous versions of VS. NET, the compiled version includes ASPX pages, ASCX files, and so on with the design, because they've been converted to classes and compiled too.

You can copy the result of this compilation to your server by using XCopy or you can ship it to your customers. After that, it isn't possible for the customer to change the application or any of the pages. (A perfect model for software licensing!)

Start the compilation with a new command-line application called spnet_compiler.exe. You'll find it in the <windir>\Microsoft.NET\Framework\ <FrameworkVersion> directory.

To compile a web site stored in the file system, just pass the path of the project and a target folder in which the compiled version of the site will be stored:

 aspnet_compiler –v / -p <source> <target> 

In later versions, the parameter –v / may not be required. It's just a workaround in the current Alpha. You can use it to define a virtual directory that will be used for absolute links.

Have a look at the result of the compilation and you'll see that it has almost the same structure as your web site (see Figure 2-19). Here you can recognize your ASPX files among other things. But they're used as marks only, and they contain just a message and no design. The documentation consists of an overview of different files and file types. Files with the extension .compile are important; they're necessary to establish the allocation between pages and the generated assemblies.

click to expand
Figure 2-19: The precompilation tool creates a marker file for each page of your site.

To transfer the web site to a server, copy the whole folder. Please don't delete any of the files—they're all required for execution.




ASP. NET 2.0 Revealed
ASP.NET 2.0 Revealed
ISBN: 1590593375
EAN: 2147483647
Year: 2005
Pages: 133

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net