Monday, March 28, 2016

Adevntures in AWS: Nested IIS configurations

I was automating some deploys of IIS apps in AWS ElasticBeanstalk using TeamCity, and had passed some Teamcity environment variables into the AWS EB environment configuration only to find that the variables did NOT exist in my app's local Web.config post-deployment! I searched around in IIS for a bit and found that they were actually being set at the web.config for the hosting web site, which by convention is 'Default Web Site'. I spent a little while wracking my brain for how to get access to those values in a way that wasn't file-read-based, because the executing user account doesn't have access outside it's hosting directory, when I came across a reference to the


static method. When used with the name of a web site, this will read and parse the config into a


object. So at last, I could use the following code to merge the two sources of settings: