Monday, March 28, 2016

Adventures 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
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration
static method. When used with the name of a web site, this will read and parse the config into a
System.Configuration.Configuration
object. So at last, I could use the following code to merge the two sources of settings: