在Azure网站中,我总是使用以下代码从config的应用程序设置中获取一些值:
string property = WebConfigurationManager.AppSettings["property"]; 就在几天前,我在CloudConfigurationManager上结结巴巴地说:
string property = CloudConfigurationManager.GetSetting("property"); 虽然CloudConfigurationManager似乎更适合于云的使用,但我对WebConfigurationManager从来没有任何问题。
发布于 2015-04-24 23:30:10
CloudConfigurationManager使我们能够读取配置文件,而不管我们所处的环境如何。
因此,与其编写特定于环境的代码语句(例如,对于web.config文件),不如:
WebConfigurationManager.AppSettings"MySetting“
对于ServiceConfiguration.cscfg文件:
RoleEnvironment.GetConfigurationSettingValue("MySetting")
我们可以编写以下语句,它将从所有配置文件(即app.config、web.config和ServiceConfiguration.cscfg )中读取值。
CloudConfigurationManager.GetSetting("MySetting")
发布于 2015-04-16 11:49:24
CloudConfigurationManager需要Microsoft.WindowsAzure.Configuration程序集、Azure的一部分或单独的NuGet。
WebConfigurationManager需要System.Web.Configuration程序集,这是.NET框架的一部分。
发布于 2015-04-15 17:58:16
WebConfigurationManager和CloudConfigurationManager管理不同的配置文件。
WebConfigurationManager用于管理网站的web.config文件及其应用程序设置和连接字符串
CloudConfigurationManager用于管理.cscfg文件(用于云服务)。他的好处是您可以直接从azure门户管理配置和连接。
https://stackoverflow.com/questions/29655648
复制相似问题