Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move config settings from web.config to ServiceConfiguration.cscfg

Tags:

c

asp.net

azure

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

like image 950
Black Eagle Avatar asked Feb 23 '23 15:02

Black Eagle


1 Answers

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.

like image 100
Jeremy McGee Avatar answered Apr 28 '23 07:04

Jeremy McGee