If you want to pre-compile the website before placing it on the live server, you can use Visual Studio's Publish function. It allows you to compile the source code into assemblies. This provides several advantages:
|•||faster application start (no compilation is required)|
|•||intellectual property protection - if someone gets your website code, they will not be able to read the source code easily|
|•||better security - the code cannot be easily modified by potential hacker|
However, there's also a disadvantage: if you compile the website, you will not be able to use some of the Kentico CMS features:
|•||import of the website|
|•||New site wizard.|
|•||You cannot add code in the Code tab of web parts (the Code tab is an obsolete feature as of Kentico CMS 3.0, it is mentioned here due to backward compatibility reasons).|
If you run a pre-compiled website, you will get the errors like:
The file '/CMSTransformations/cms/event/preview.ascx' does not exist.
This means that the system requires a virtual object, but the VirtualPathProvider is probably not running and cannot provide the system with that object.
Pre-compiling the website
Please note that for building the pre-compiled website, you have to rename Microsoft.Web.Services3.dll.rename file to Microsoft.Web.Services3.dll in the ~\Bin directory.
Since the virtual provider cannot run in a pre-compiled website, you need to store the physical files to the system before compilation. You can save all the virtual objects to the file system in CMS Site Manager -> Administration -> System -> Deployment interface by clicking the button “Save all virtual objects to disk”.
Please note that these files are just copies of the actual virtual object and will be used by the system only if the VirtualPathProvider cannot start. Also, the changes to the objects through the administration interface will not affect these files until you save all the objects to the disk again.
Then, you can use Build -> Publish item in Visual Studio main menu and pre-compile the website. You will see a dialog like this:
You need to enter the path outside your current web project where the compiled version will be placed. You can choose between two compilation modes using the Allow this precompiled site to be updatable checkbox:
|•||Allow the site to be updatable (checked) - the code behind and app_code classes are compiled, but ASPX files are stored in their original source code form.|
|•||Do not allow the site to be updatable (unchecked) - the code behind and app_code, as well as ASPX files are compiled and the website contains only empty "stub" ASPX files without any code.|
We generally recommend that you do not allow the site to be updatable, since it provides the best performance.
In the precompiled website, the VirtualPathProvider is stopped automatically. When VirtualPathProvider is stopped, you cannot edit transformations and layouts through the user interface without saving them on the disk again.
You may need to copy the database to the server using the standard backup/restore operation since the compiled website cannot be used for SQL Server database installation. Other options are:
In the portal development model, you cannot use custom web part code (Web part properties –> Code tab). If you need to add custom code on the Code tab and run the website in the compiled version, you need to create user controls, place web parts to the user controls and add your custom code to the web parts. Then, you can place the user controls to the page using the General/User control web part.
Testing the website before compilation
If you wish to check if your website runs without using VirtualPathProvider (to simulate the precompiled environment), you can disable the provider by adding the following key into the appSettings section of your web.config file:
If your system runs with VirtualPathProvider disabled, you should be able to run it after the precompilation or deployment process.
Related topics: Additional configuration tasks -> Configuration for Medium Trust environment, Installation procedure -> Deployment to the live server, Additional configuration tasks -> Installation on shared hosting server