Azure的类库访问GetConfigurationSettingValue与web.config中 [英] Azure class library access GetConfigurationSettingValue vs. web.config

查看:184
本文介绍了Azure的类库访问GetConfigurationSettingValue与web.config中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个蓝色的工作者角色和一个ASP.NET网站之间共享的类库。库中的一种方法,需要从配置拉一个值,以确定它是否应该发送电子邮件或没有。

I have a class library shared between an Azure Worker Role and a ASP.NET Website. A method in the library needs to pull a value from the config to determine if it should send an email or not.

在ASP.NET网站,设置为在web.config中:

In the ASP.NET site, the setting is in web.config:

<add key="SendEmails" value="true"/>

而在Azure的工作者角色是在ServiceConfiguration.Cloud.cscfg:

And in the Azure worker role it is in ServiceConfiguration.Cloud.cscfg:

<Setting name="SendEmails" value="true"/>

我所试图做的是有我的类库能够访问任何配置设置,取决于其下运行什么样的环境。

What I am trying to do is have my class library be able to access either config setting, depending on what environment it is running under.

推荐答案

创建自己的类来检索配置值,并在其中你就会有这样的内容:

Create your own class to retrieve configuration values and in it you'll have items like this:

if (RoleEnvironment.IsAvailable)
 return RoleEnvironment.GetConfigurationSettingValue("mySetting");
else
 return ConfigurationManager.AppSettings["mySetting"].ToString();

RoleEnvironment.IsAvailable将检测应该是,如果你在Windows Azure结构是检测并返回true。这将要求您在您的ASP.NET项目Microsoft.WindowsAzure.ServiceRuntime装配/参鉴。

RoleEnvironment.IsAvailable will detect is supposed to detect if you're in the Windows Azure fabric and return true. It will require that you include the Microsoft.WindowsAzure.ServiceRuntime assembly/referrence in your ASP.NET project.

我做<一个href=\"http://brentda$c$cmonkey.word$p$pss.com/2011/10/08/configuration-in-azure-year-of-azureweek-14/\">a关于这一主题的博客文章,如果你想了解更多信息。

I did a blog post on this topic if you want more information.

这篇关于Azure的类库访问GetConfigurationSettingValue与web.config中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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