Thursday, December 20, 2007

Hide your website source code. PreCompile your site before deploy.

Suppose you want to deploy asp.Net website without deploying any source code to webserver. This can be achieve in the following way.

Aspnet_compiler.exe (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ Aspnet_compiler.exe) can help you to achieve this goal.

Step 1.

Run following command in command prompt of the webserver:

Aspnet_compiler -p "D:\MyWEbSite" -v / c:\OnlyAssembly

Here,

D:\MyWEbSite is the path where my website source code resides

c:\OnlyAssembly is the path where assembly dlls will be generate


 

Step 2

The command will generate the required .dlls and .config files under the folder c:\OnlyAssembly.

Step 3.

Create a virtual directory in IIS and map this directory with that virtual directory.

Step 4.

Your application is deployed on the server without any source code to be deployed on the server. Open the website and browse it ahead!!!


 

NOTEs:

  1. If you open an ASPX file in a pre-compiled target directory you'll see the following content: "This is a marker file generated by the precompilation tool, and should not be deleted!"


     

  2. For some people, the ability to update content on the web server by modifying aspx and ascx files is a needed feature. To support this scenario, the aspnet_compiler has the –u switch for an "updateable" pre-compilation. With updateable pre-compilation the ASPX, ASCX, ASHX, and MASTER files are copied to the target directory in tact - they do not become 'marker' files. You can deploy these files to the server and modify them without causing an error, because the ASP.NET runtime will dynamically parse and compile these files. All of the source code for code-behind files and in the App_Code folder will still be compiled into assemblies and will not need to be deployed.


     

  3. A benefit to pre-compilation for deployment is that no one can make changes to the web application by tweaking the source code – no source code exists!


     

Please revert back if any queries.


 

Thanking You,

Indrajeet Kumpavat.

indrajitk@gmail.com