在Elastic Beanstalk Web.config中访问ASP.NET MVC变量 [英] Accessing ASP.NET MVC Variables in Elastic Beanstalk Web.config

查看:69
本文介绍了在Elastic Beanstalk Web.config中访问ASP.NET MVC变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用用于生产服务器,密码等的自定义web.config密钥来更新我的Elastic beantalk配置.

I'm trying to update my elastic beanstalk configuration with custom web.config keys for our production servers, passwords, etc.

根据这些.NET文档 ,我可以使用ConfigurationManager.AppSettings来访问这些变量.我的本地计算机上有一些默认值,这些默认值是可以读取的,而不是Web UI中的替代值.

According to these .NET docs, I can use ConfigurationManager.AppSettings to access these variables. I have some defaults that are in there for my local machine, and these are what get read, instead of the overrides in the web UI.

通过在输入框中输入最多五个其他键值对来指定它们 参数框.

Specify up to five additional key-value pairs by entering them in the PARAM boxes.

您可能有一个类似于以下内容的代码段: 访问键和参数:

You might have a code snippet that looks similar to the following to access the keys and parameters:

NameValueCollection appConfig = ConfigurationManager.AppSettings;
string param1 = appConfig["PARAM1"];

如何在Elastic Beanstalk中访问我的web.config替代?

How do I access my web.config overrides in Elastic Beanstalk?

推荐答案

事实证明,仅当web.config中不存在配置变量时,才会添加配置变量.这与我在Azure中遇到的行为不同,在Azure中,参数将覆盖web.config.

It turns out that the configuration variables will only be added if they do not previously exist in web.config. This is a different behavior than I have experienced in Azure, where parameters would override web.config.

您可以通过RDP进入EC2实例并查看web.config来对此进行验证.将添加新参数,但将忽略web.config中存在的参数.

You can validate this by RDP'ing into an EC2 instance, and viewing web.config. New parameters will be added, but ones that exist in web.config will be ignored.

您可以通过使用Web.Release.Config中的xdt删除"转换来复制替代行为

You can replicate the override behavior by using the xdt "Remove" Transform in Web.Release.Config

 <add key="foo" xdt:Transform="Remove" xdt:Locator="Match(key)"/>

然后使用Web工具,文件配置或CLI在Elastic Beanstalk中设置"foo"参数

Then set the "foo" parameter in Elastic Beanstalk using the web tool, file config, or CLI

这篇关于在Elastic Beanstalk Web.config中访问ASP.NET MVC变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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