Skip to main content

Why it is important to use Windows Azure Service Configuration Schema and not application configuration section from web.config or app.config

Knowing where to store the configuration of an application is very important. This can give the ability to a provider to switch the behavior of an application very fast and easily.
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.


Popular posts from this blog

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine:
threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration:

TeamCity.NET 4.51EF 6.0.2VS2013
It seems that there …

Entity Framework (EF) TransactionScope vs Database.BeginTransaction

In today blog post we will talk a little about a new feature that is available on EF6+ related to Transactions.
Until now, when we had to use transaction we used ‘TransactionScope’. It works great and I would say that is something that is now in our blood.
using (var scope = new TransactionScope(TransactionScopeOption.Required)) { using (SqlConnection conn = new SqlConnection("...")) { conn.Open(); SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = conn; sqlCommand.CommandText = ... sqlCommand.ExecuteNonQuery(); ... } scope.Complete(); } Starting with EF6.0 we have a new way to work with transactions. The new approach is based on Database.BeginTransaction(), Database.Rollback(), Database.Commit(). Yes, no more TransactionScope.
In the followi…

GET call of REST API that contains '/'-slash character in the value of a parameter

Let’s assume that we have the following scenario: I have a public HTTP endpoint and I need to post some content using GET command. One of the parameters contains special characters like “\” and “/”. If the endpoint is an ApiController than you may have problems if you encode the parameter using the http encoder.
using (var httpClient = new HttpClient()) { httpClient.BaseAddress = baseUrl; Task<HttpResponseMessage> response = httpClient.GetAsync(string.Format("api/foo/{0}", "qwert/qwerqwer"))); response.Wait(); response.Result.EnsureSuccessStatusCode(); } One possible solution would be to encode the query parameter using UrlTokenEncode method of HttpServerUtility class and GetBytes method ofUTF8. In this way you would get the array of bytes of the parameter and encode them as a url token.
The following code show to you how you could write the encode and decode methods.