无法从Web.Config中读取appSettings值
我在web.config中有以下内容:
. . .
我的代码隐藏中有以下代码:
System.Configuration.Configuration webConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null) ;
但是,当我查看webConfig时,webConfig.AppSettings.Settings.Count = 0。
为什么不读取应用程序设置?
我想做的是能够通过使用以下方式获取设置:
System.Configuration.KeyValueConfigurationElement psych = webConfig.AppSettings.Settings["PsychMon"];
我使用c#3.5,vs 2008
你为什么不写这个?
string value = System.Web.Configuration.WebConfigurationManager.AppSettings["PsychMon"];
试试这个 :
ConfigurationManager.AppSettings["PsychMon"];
或(对于全球)
Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
而不是创建webConfig
变量,为什么不使用ConfigurationManager.AppSettings["PsychMon"]