Accessing ASP.NET MVC Variables in Elastic Beansta

2019-02-10 22:51发布

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

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"];

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

1条回答
Summer. ? 凉城
2楼-- · 2019-02-10 23:41

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.

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.

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)"/>

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

查看更多
登录 后发表回答