I have searched the site, and while I found some very useful information, I couldn\'t figure out what is going on with my code. I have the following web.config:
Are you sure that you're using the correct Web.Config file? You probably want to use the one at the application root, not the one in the Views directory.
ASP.NET MVC and two Web.config files
Have you tried using the WebConfigurationManager:
return System.Web.Configuration.WebConfigurationManager.AppSettings["APIKey"];
This is the preferred option for using config files in a web app - it handles things like nested config files, etc.
Have you tried:
return ConfigurationManager.AppSettings.Get("APIKey");
Visual Studio creates 2 web.config files for MVC. 1 at the root, and the other in the Views folder.
Does your machine.config have the requisite AppSettings section. It should look something like (version numbers would be different):
<configuration>
<configSections>
<section name="appSettings"
type="System.Configuration.NameValueFileSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
</configuration>
Are you sure you're using the correct web.config? What does ConfigurationManager.AppSettings.Settings look like?
Check to make sure the Build Action of the web.config file is "None". I have seen this problem if the build action is "Embedded Resource".