如何阅读弹性青苗环境属性在.net中? [英] How to read Elastic Beanstalk Environment Properties in .net?
问题描述
我怎样才能从我的AWS弹性魔豆阅读应用环境属性在这里找到:
How can I read the Environment Properties from my AWS Elastic Beanstalk Application found here:
Configuration > Software Configuration > Environment Properties
以下方法无工作:
ConfigurationManager.AppSettings["MyServiceUrl"]
ConfigurationManager.AppSettings["aws:elasticbeanstalk:application:environment.MyServiceUrl"]
Environment.GetEnvironmentVariable("MyServiceUrl")
Environment.GetEnvironmentVariable("aws:elasticbeanstalk:application:environment.MyServiceUrl")
在'完全合格的名字企图来自 AWS EB文档。
任何想法?
推荐答案
在你的 .ebextensions / myoptions.config
文件:
option_settings:
- option_name: MyServiceUrl
value: change me
这会在你的EB环境属性部分添加MyServiceUrl选项(如你看到的话)。在部署时,这将以下内容添加到您的的Web.Config
文件:
This will add the "MyServiceUrl" option in your EB Environment Properties section (as you're seeing already). When deployed, this will add the following to your Web.Config
file:
<appSettings>
<add key="MyServiceUrl" value="change me" />
</appSettings>
如果您RDP到您的EC2实例,你会看到这一点。
If you RDP into your EC2 instance, you'll see this.
当您更改使用EB控制台属性的设置将在的Web.Config修改
文件。
When you change the property using the EB console, the setting will be modified in your Web.Config
file.
所以,你使用标准的访问此属性的AppSettings
方法:
So you access this property using the standard AppSettings
method:
string value = ConfigurationManager.AppSettings["MyServiceUrl"];
美中不足的是:
您需要确保你的的Web.Config
文件不包含此设置,否则EB不会取代它。如果您的Visual Studio部署软件包中包含此设置,那么EB不会取代它,当您通过code访问属性,你将永远收到部署的值。
You need to ensure that your Web.Config
file does not contain this setting, otherwise EB does not replace it. If your Visual Studio deployment package includes this setting, then EB will not replace it and you will always receive the deployed value when you access the property via your code.
解决方案:
在您 Web.Release.config
文件的Visual Studio部署过程中设置删除:
In you Web.Release.config
file, have the setting removed during Visual Studio deployment:
<appSettings>
<add key="MyServiceUrl" xdt:Transform="Remove" xdt:Locator="Match(key)" />
</appSettings>
这将Visual Studio的部署过程中删除的Web.Config
设置,将使EB到EB部署过程中添加值到文件中。
This will remove the setting from Web.Config
during Visual Studio deployment and will allow EB to add the value into the file during EB deployment.
这篇关于如何阅读弹性青苗环境属性在.net中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!