gpt4 book ai didi

c# - 无法从 Web.Config 读取 appSettings 值

转载 作者:太空狗 更新时间:2023-10-29 22:11:00 25 4
gpt4 key购买 nike

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

<configuration>
<appSettings>
<add key="PsychMon" value="true"/>
</appSettings>
. . .
</configuration>

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

  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,对比 2008

最佳答案

你为什么不写这个?

string value = 
System.Web.Configuration.WebConfigurationManager.AppSettings["PsychMon"];

关于c# - 无法从 Web.Config 读取 appSettings 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11651005/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com