6.3. Precompile Your Site
In ASP.NET 1.x, you deploy files with .aspx extensions to the web server that hosts the application. To safeguard your business logic, ASP.NET does not require you to deploy the code-behinds of your Web Forms. However, the user interface of your web application is still encapsulated within the .aspx file, and these files must be deployed to the web server, opening the possibility that someone at the web server end (especially for web hosting scenarios) may read your UI code. ASP.NET 2.0 has gone a step further, allowing you to precompile a site so that when you deploy it:
Note: You can now precompile and deploy your ASP.NET web application without exposing the source, thereby improving first user response time and protecting your IP.
Tip: If your web application uses client-side scripts, they would still be visible on the user's web browser side, since they have to be sent to the web browser for processing.
6.3.1. How do I do that?
ASP.NET 2.0 supports two precompilation options:
Precompile for site deployment allows to you to deploy the compiled binaries of your web site to the hosting machine without the need to deploy your source code. This is a great boost to protecting your source, especially when you are deploying to a remote hosting machine and do not want others to see the source code behind your web site. It also precompiles the site and so reduces the first-use response time of the application.
Let's see how you can precompile a site for deployment.
6.3.2. What about...
That's certainly possible. Precompile In-Place allows you to precompile a web site before the user loads the page. Traditional ASP.NET pages are dynamically compiled and cached the first time a user loads the page, so the load time is always higher the first time the site is accessed. With precompilation, the web site is compiled and cached before a user loads a page for the first time, eliminating the long wait for the page to be compiled. Another benefit to this approach is the ability to check for bugs before the user discovers them.
Note: Precompile In-Place is useful for web sites that change often.
To precompile your site before the first user loads it, you simply invoke the special handler precompile.axd located in the virtual root of your web application, like this:
After precompilation, you will notice that there are no delays when the application is first accessed.
Tip: Precompiling works by compiling the entire site (including subdirectories).
...hackers launching a denial-of-service attack at my site by forcing it to constantly precompile?
ASP.NET 2.0 will turn off remote precompiling in-place. You can only perform a precompile in-place locally.
...updating an application once I have precompiled it?
Once you have precompiled an application, you can only deploy the directory that has been generated. To update an application, you would need to modify the original application files and perform the precompilation steps again.
6.3.3. Where can I learn more?
To learn how you can precompile ASP.NET 1.x applications, check out the article at http://www.codeproject.com/aspnet/PreCompileAspx.asp.