I have some application settings in my Web.config file, for sending email from within the system. The relevant part reads:
<configuration>
...
<appSettings>
<add key="webpages:Enabled" value="false" />
<add key="emailRecipient" value="my email"/>
<add key="emailSubject" value="subject"/>
(other settings for contacting the mail server)
</appSettings>
...
</configuration>
And in my repository, I use it like so:
using System.Web.Configuration;
MailModel email = new MailModel();
email.EmailTo = WebConfigurationManager.AppSettings["emailRecipient"];
email.Subject = WebConfigurationManager.AppSettings["emailSubject"];
Plus other lines to get the settings to contact the mail server.
The problem I'm having is that in the debugger, WCM.AppSettings
contains 5 values:
WebConfigurationManager.AppSettings.AllKeys
{string[5]}
[0]: "webpages:Version"
[1]: "webpages:Enabled"
[2]: "PreserveLoginUrl"
[3]: "ClientValidationEnabled"
[4]: "UnobtrusiveJavaScriptEnabled"
What happened to my email config settings?
I checked with two other Stack Overflow questions to make sure I didn't make any obvious mistakes. (How to read appSettings section in the web.config file? and Can't read appSettings value from Web.Config) So the problem is not obvious.
Edited to add:
I found my problem, and it's a bit embarrassing. I had put the settings into ~/Views/Web.config
instead of ~/Web.config
. Once I fixed that, the settings worked properly. Mods, please close.