无法从Web.Config中读取appSettings值

Lil*_*sey 5 c# web-config

我在web.config中有以下内容:

<configuration>
    <appSettings>
        <add key="PsychMon" value="true"/>
    </appSettings>
 . . .
</configuration>
Run Code Online (Sandbox Code Playgroud)

我的代码隐藏中有以下代码:

  System.Configuration.Configuration webConfig = 
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null) ; 
Run Code Online (Sandbox Code Playgroud)

但是,当我查看webConfig时,webConfig.AppSettings.Settings.Count = 0.

为什么不读取应用程序设置?

我想做的是能够通过使用以下方式获取设置:

          System.Configuration.KeyValueConfigurationElement psych = 
webConfig.AppSettings.Settings["PsychMon"];
Run Code Online (Sandbox Code Playgroud)

我正在使用c#3.5,而不是2008

yog*_*ogi 12

你为什么不写这个?

string value = 
    System.Web.Configuration.WebConfigurationManager.AppSettings["PsychMon"];
Run Code Online (Sandbox Code Playgroud)