Azure web/worker role read configuration settings

亡梦爱人 提交于 2019-11-27 13:03:38

问题


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

Is it:

CloudConfigurationManager.GetSetting("ConnectionString") (this I'm using)

or

RoleEnvironment.GetConfigurationSettingValue("ConnectionString")

Although both work fine ...


回答1:


From the documentation for CloudConfigurationManager.GetSetting:

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.

From above, it is clear that the function CloudConfigurationManager.GetSetting reads either from service configuration (ServiceConfiguration.cscfg) file or application configuration file (App.config/Web.config) depending on where the application is running.

RoleEnvironment.GetConfigurationSettingValue will only read from the 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.



来源:https://stackoverflow.com/questions/19643383/azure-web-worker-role-read-configuration-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!