I have the following in my web.config:
<configuration>
<appSettings>
<add key="PsychMon" value="true"/>
</appSettings>
. . .
</configuration>
I have the following code in my codebehind:
System.Configuration.Configuration webConfig =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null) ;
However, when I look at webConfig, webConfig.AppSettings.Settings.Count = 0 .
Why is it not reading the app setting?
What I want to do is be able to get the setting by using:
System.Configuration.KeyValueConfigurationElement psych =
webConfig.AppSettings.Settings["PsychMon"];
I am using c# 3.5, vs 2008
The key/value pairs specified in the <appSettings> element are accessed in code using the ConfigurationSettings class. You can use the file attribute in the <appSettings> element of the Web. config and application configuration files.
Why appsettings keys (in web. config) are not case sensitive ? The default comparer is a CaseInsensitiveComparer that uses the conventions of the invariant culture; that is, key comparisons are case-insensitive by default.
The IConfiguration is an interface for . Net Core 2.0. The IConfiguration interface need to be injected as dependency in the Controller and then later used throughout the Controller. The IConfiguration interface is used to read Settings and Connection Strings from AppSettings. json file.
Why don't you just write this ?
string value =
System.Web.Configuration.WebConfigurationManager.AppSettings["PsychMon"];
try this :
ConfigurationManager.AppSettings["PsychMon"];
or ( for global)
Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With