Azure的网络/辅助角色读取配置设置

问题描述:

什么是从工人/ Web角色读设置的最佳方法/推荐的方式?

What is the best way/recommended way to read settings from a worker/web role?

它是:

CloudConfigurationManager.GetSetting(的ConnectionString)(这我使用)

RoleEnvironment.GetConfigurationSettingValue(的ConnectionString)

虽然两者做工精细...

Although both work fine ...

从CloudConfigurationManager.GetSetting$c$c>:

该GetSetting方法读取配置与设定值
  适当配置存储。如果应用程序运行为
  .NET Web应用程序中,GetSetting方法将返回设置
  从Web.config或app.config文件的价值。如果该应用程序是
  在Windows Azure云服务或在Windows Azure中运行的网站,
  该GetSetting将返回从设定值
  ServiceConfiguration.cscfg。

The GetSetting method reads the configuration setting value from the appropriate configuration store. If the application is running as a .NET Web application, the GetSetting method will return the setting value from the Web.config or app.config file. If the application is running in Windows Azure Cloud Service or in a Windows Azure Website, the GetSetting will return the setting value from the ServiceConfiguration.cscfg.

从以上,很明显,该函数要么从服务配置文件或应用程序配置文件(的app.config / web.config中),这取决于应用程序正在运行,其中读取,其中如RoleEnvironment.GetConfigurationSettingValue$c$c>将只从服务配置文件中读取。如果你的应用组件是在云和非云应用中,使用 CloudConfigurationManager.GetSetting ,这样你就不必做了code的任何变化。如果您的组件将在云中只运行,那么我想你可以使用任何一个

From above, it is clear that this function either reads from service configuration file or application configuration file (app.config/web.config) depending on where the application is running where as RoleEnvironment.GetConfigurationSettingValue will only read from service configuration file. If your application component is used in both cloud and non-cloud applications, use CloudConfigurationManager.GetSetting so that you don't have to make any changes in the code. If your component would run only in the cloud, then I guess you could use either one