asp.net - How to read Elastic Beanstalk Environment Properties in .net? -


how can read environment properties aws elastic beanstalk application found here:

configuration > software configuration > environment properties 

enter image description here

none of following approaches work:

configurationmanager.appsettings["myserviceurl"] configurationmanager.appsettings["aws:elasticbeanstalk:application:environment.myserviceurl"] environment.getenvironmentvariable("myserviceurl") environment.getenvironmentvariable("aws:elasticbeanstalk:application:environment.myserviceurl") 

the 'fully qualified' name attempt comes aws eb documentation.

any ideas?

in .ebextensions/myoptions.config file:

option_settings:   - option_name: myserviceurl     value: change me 

this add "myserviceurl" option in eb environment properties section (as you're seeing already). when deployed, add following web.config file:

<appsettings>   <add key="myserviceurl" value="change me" /> </appsettings> 

if rdp ec2 instance, you'll see this.

when change property using eb console, setting modified in web.config file.

so access property using standard appsettings method:

string value = configurationmanager.appsettings["myserviceurl"]; 

the catch:

you need ensure web.config file not contain setting, otherwise eb not replace it. if visual studio deployment package includes setting, eb not replace , receive deployed value when access property via code.

the solution:

in web.release.config file, have setting removed during visual studio deployment:

<appsettings>   <add key="myserviceurl" xdt:transform="remove" xdt:locator="match(key)" /> </appsettings> 

this remove setting web.config during visual studio deployment , allow eb add value file during eb deployment.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -