Azure的网络/辅助角色读取配置设置 [英] Azure web/worker role read configuration settings

查看:180
本文介绍了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 ...

推荐答案

从<一个文档href=\"http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.cloudconfigurationmanager.getsetting.aspx\"><$c$c>CloudConfigurationManager.GetSetting:

该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中),这取决于应用程序正在运行,其中读取,其中如<一个href=\"http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.getconfigurationsettingvalue.aspx\"><$c$c>RoleEnvironment.GetConfigurationSettingValue将只从服务配置文件中读取。如果你的应用组件是在云和非云应用中,使用 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

这篇关于Azure的网络/辅助角色读取配置设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆