Web Config Shenanigans

One of the things that I love about IT is that it (small this time) is like a huge puzzle. I’ve probably said this before, but I get enormous satisfaction out of solving problems and understanding how that little obstacle that is in front of me can be decomposed and dissected until I fully grasp its metal :-) Well, that’s what I just had today.

It was a cold morning in London and here I was, minding my own configuration business, adding in app settings to try and make my project more flexible. This is a small snippet of what I added into my web.config file:

<appSettings>
<add key="xmlOutputPath" value="F:\\"/>
</appSettings>

Pretty straight forward, right? So why couldn’t I read that setting when I did this:

string folder = WebConfigurationManager.AppSettings["xmlOutputPath"];

Each time, I got the dreaded null. Did I make a typo with the name? Nope. Were my appSettings correct XML? Yes, besides, VS would have complained. Do I even have a value? Err. Definitely. I know, maybe I should be using ConfigurationManager instead. No, that can’t be right - this is a web project. So what could it be? Here, you can see a screenshot of my config file.

And that, dear reader, sums up the problem!

#MakeSureYouEditTheRightConfigFile


Hi! Did you find this useful or interesting? I have an email list coming soon, but in the meantime, if you ready anything you fancy chatting about, I would love to hear from you. You can contact me here or at stephen ‘at’ logicalmoon.com