简体   繁体   中英

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM