Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing ASP.NET MVC Variables in Elastic Beanstalk Web.config

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?

like image 615
Doug Avatar asked Nov 11 '13 22:11

Doug


Video Answer


1 Answers

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

like image 139
Doug Avatar answered Oct 26 '22 06:10

Doug