22.9. Precompile If You're Code Shy
NOTE
If it bothers you that someone might rummage around on the Web server and read your source code, consider precompiling the site. Normally, ASP.NET compiles the code the first time someone requests a page. With precompilation, ASP.NET puts the code from the .aspx, .asmx, .ascx, and .vb files into a few assemblies (.dll files) in the bin folder. Follow these steps to compile your Web project:
Open your project in Visual Web Developer and build the site (Build
Build Web Site) to see any errors or warnings that need attention (View
Error List).Precompilation fails if the project has errors, so fix or exclude troublesome pages.
Open a command prompt in the directory where aspnet_compiler.exe is installed. (Try C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727.)
At the command prompt, enter the following command, replacing c:\site\kjopc with the path to your Web files:
aspnet_compiler -v /myweb -p c:\site\kjopc c:\deploy
The preceding command compiles and then copies the required files (including images and other static content) into a new c:\deploy folder. The compiled files appear in the bin folder.
NOTE
Although the .aspx files copy to the c:\deploy folder, no code or markup is in them — just the warning text: This is a marker file generated by the precompilation ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access