Black Eagle
Black Eagle

Reputation: 1117

Move config settings from web.config to ServiceConfiguration.cscfg

If I am moving config settings from my Web.config to Aazure ServiceConfiguration.cscfg, Do I need to make any code changes

For Example my I have the below mentioned entries in my Web.config

<ConfigurationSettings> <Setting name="webConfigHostName" value="Test.AzureTest" /> </ConfigurationSettings>

To read the above entry,I use

string myHostName=MyEnvironmentWrapper.GetConfigurationSettingValue("webConfigHostName");

Now I want to move my web application to Azure Cloud Environment

So I am planning to move the above web.config entries to my ServiceConfiguration.csfg After this do I need to make any code changes so that my application can read "webConfigHostName" directly from my ServiceConfiguration.csfg

Upvotes: 4

Views: 3885

Answers (1)

Jeremy McGee
Jeremy McGee

Reputation: 25200

I'm afraid (in the old days, see below) you did:

if (RoleEnvironment.IsAvailable)
{
    return RoleEnvironment.GetConfigurationSettingValue("mySetting");
}
else
{
    return ConfigurationManager.AppSettings["mySetting"].ToString();
    // or whatever your configuration system requires
}

There are some great posts on this here and here.

We ended up writing our own wrapper around this to make our application agnostic, so in our code we use a static Configuration.GetValue(). A quick global search-and-replace and we were away.


EDIT: Today this is easier: see the MSDN reference for the CloudConfigurationManager.

Upvotes: 8

Related Questions