我建立了一个使用Web.config获取一些appSettings的WCF服务。在Visual Studio中,它运行得很好,但是当我发布和安装服务后,它突然从App.config而不是Web.config获取其appSettings。
我知道这是因为我使用以下代码循环遍历appSettings并将结果打印到控制台:
foreach (string key in ConfigurationManager.AppSettings.AllKeys)
{
Console.WriteLine("Name: {0} Value: {1}", key, ConfigurationManager.AppSettings[key]);
}
我的配置看起来像这样:
Web.config文件:
....
<appSettings>
<add key="IQDir" value="C:\Program Files (x86)\Ridder iQ Client (lokaal)\Bin"/>
<add key="FileURL" value="localhost:8080/WebPortal_2.0/"/>
</appSettings>
....
App.config
....
<appSettings>
<add key="test1" value="wtf is going on!"/>
<add key="test2" value="waargh"/>
<add key="test3" value="I am getting a headache over here!!"/>
</appSettings>
....
当我在Visual Studio中运行时,会出现以下情况:
![enter image description here](https://istack.dev59.com/OLMUZ.webp)
![enter image description here](https://istack.dev59.com/6PgR8.webp)
ConfigurationManager
从Web.config获取appSettings而不是App.config?
System.Web.Configuration.WebConfigurationManager
了吗? - TobberothWebConfigurationManager
。结果都一样。 - botenvouwer