Why it is important to use Windows Azure Service Configuration Schema and not application configuration section from web.config or app.config
When you are developing a web application that will be hosted on Windows Azure, you have the possibility to store the configuration values in the web.config file of in the settings section of the role (from Windows Azure project). The same thing is for the case when you have a non-web application that has an app.config file. Of course we have the 3th option to put the content in a custom repository (file, database or so on), but we’ll focus on the first two options.
I saw a lot of project, where people ignored the configuration section of Windows Azure project. Also, they are used to store all the content in the web.config/app.config files, they don’t look to the new location where you can store them.
When you have the content store in the classic configuration file, you don’t have the ability to change the value of different settings without accessing remotely the machine or ISS configuration. Switching a settings from ON to OFF will required to access the machine remotely and change the configuration manually.
But what about if you have 20 instances. Well, you will need to do the same thing for 20 times or write a script. Some people will say that in this case they would put all the settings in a central repository from where all the instances can read the configuration (Azure Blobs, Azure Tables or a classic database).
All this solution are good and will work, but you need to write code, to configure in a different way all the application and from where the settings are read.
But, if we look closed to Windows Azure project we’ll see that we have a settings section for each role. We can add any kind of settings there. Above this we have another big advantage. From Windows Azure you can change the value of the settings.
This mean that you only need to go to portal, change the value of one settings key and all the instances of the roles will be able to access the new value of it. Beside this you have the possibility to export on your local system the settings configuration or import it from a custom source (you can and up with different profiles).
Another advantage of this is that the configuration settings is not ‘hardcoded’ in the package that is generated for the role.
Why is this so important? Well, when a role is reset or a new instances is created, the original package is used to deploy the application binaries. This mean that even if you change the web.config/app.config at runtime, the change will not be persisted when the role is reset or a new instance is created. To be able to persist the change, you will need to redeploy the application.
In contrast, when you have the settings in the configuration section of the role, you can reset the role, you can create as many new instances you want without changing you custom configuration. The only time when you lose this configuration is when you redeploy the project, but this is a normal behavior, because you publish a new version of the application.
In this post we saw why it is so important to use the configuration settings from Windows Azure project (roles) and not the one from the application configuration files.
In the next post we will see how we can detect automatically when the configuration settings from roles were changed.