How do I check a setting exists in the web.config file?
I found the following code, however i think it is aimed at an app.config file? where as my settings are in web.config. The below code returns no keys even though there are 6.
if (ConfigurationManager.AppSettings.AllKeys.Contains(settingName))
{
return 1;
}
else
{
return 0;
}
Example settings in web.config:
<configuration>
. . .
<applicationSettings>
<ProjectNameSpace.Properties.Settings>
<setting name="mySetting" serializeAs="String">
<value>True</value>
</setting>
</ProjectNameSpace.Properties.Settings>
</applicationSettings>
</configuration>
Originally i was trying to read it out, and check if it errors or exists.
var property = Properties.Settings.Default.Properties[settingName];
But that line of code seems to load from the web.config, and if it doesn't exist, it gets it from the project settings. So I cant tell if it is in the web.config or not by checking the value is blank, as it is set to something else!
configurationin the xml. I struggle to find resources for a solution. they are all appsettings related