The online home of Brave Location Services Ltd.

ASP.Net Compilation Tool - do you want to allow updates without redeploying?

Originally posted on my old MSDN blog

We found an interesting issue today regarding our use of pre-compiled ASP.Net websites that I thought I would share, as we learnt something that we didn’t know before.

In our particular setup (for reasons too complicated to go into here), we have an ASP.Net website that:

  1. We want to pre-compile before deploying to the live servers for the usual reasons of performance (no delay on first hit) and security (source code not hosted on the servers)
  2. Before starting the web application, we automatically generate its web.config file
  3. By default we want to disable view state in all the pages by adding a <pages enableViewState=”false” /> node in the generated web.config

Our issue was that even though the generated web.config file had the correct setting in it, the view state wasn’t being disabled. This had us confused for quite a while.

It turns out that the default setting when a website is compiled by the ASP.Net compiler doesn’t allow subsequent updates to the site.

In our particular case, this meant the compiled pages were using the (default) value in our non-existent web.config at compile time, not the one actually on the server at runtime.

Once we realised that, the solution was easy: simply add a –u parameter to the compiler flags which meant:

-u specifies that the Aspnet_compiler.exe should create a precompiled application that allows subsequent updates of contents such as .aspx pages.

If this option is omitted, the resulting application contains only compiled files and cannot be updated on the deployment server. You can update the application only by changing the source markup files and recompiling.

(Stolen from http://msdn.microsoft.com/en-us/library/ms229863(VS.80).aspx from where you can see all the available compiler parameters)

I guess a more common scenario is that you want to hot fix your web.config file – perhaps your database connection strings need changing immediately – but unless you’ve compiled with the –u flag, you’ll have to do a full build and redeployment.