Q89. Configure the .Net application for using storage emulator?

We can set the CloudStorageAccount with the default development storage account in the code using the CloudStorageAccount object’s property DevelopmentStorageAccount as shown below.

StorageAccount = CloudStorageAccount.DevelopmentStorageAccount;

Though, setting the storage account details in the application code is easy, it is not recommended because we have to modify and recompile the code each time we deploy the application to the cloud. The recommended practice is to store this information in the service configuration file. We can upload only the service configuration file whenever it is changed.

The StorageClient library provides methods using which we can extract configuration settings as shown below.

CloudStorageAccount storageaccount  = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting(“StorageConnectionString”));

In the above code, account details are extracted from the configuration setting named StorageConnectionString. After that, we create a CloudStorageAccount object by parsing a connection string. Note that we need to firstly define all configuration settings in the service definition file, and only then we can configure the settings.

The following code defines the storage account in your service definition file.


After defining the configuration settings, we can set the values in the service configuration file. The following configuration settings are set for this example.


When we set the value of StoargeConnectionString to UseDevelopmentStorage=true, we are configuring the application to use the development storage.