简体   繁体   English

将配置设置从web.config移动到ServiceConfiguration.cscfg

[英]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 如果我将配置设置从我的Web.config移动到Aazure ServiceConfiguration.cscfg,我是否需要进行任何代码更改

For Example my I have the below mentioned entries in my Web.config 例如,我在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 现在我想将我的Web应用程序移动到Azure云环境

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 所以我打算将上面的web.config条目移动到我的ServiceConfiguration.csfg之后,我需要进行任何代码更改,以便我的应用程序可以直接从我的ServiceConfiguration.csfg读取“webConfigHostName”

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() . 我们最终编写了我们自己的包装器以使我们的应用程序不可知,因此在我们的代码中我们使用静态Configuration.GetValue() A quick global search-and-replace and we were away. 快速的全球搜索和替换,我们离开了。


EDIT : Today this is easier: see the MSDN reference for the CloudConfigurationManager . 编辑 :今天这更容易:请参阅CloudConfigurationManager的MSDN参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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