我需要从App.config文件中获取"http://example.com"。
但目前我正在使用:
string peopleXMLPath = ConfigurationManager.AppSettings["server"];
我无法获取该值。
你能指出我做错了什么吗?
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configSections>
<section name="device" type="System.Configuration.SingleTagSectionHandler" />
<section name="server" type="System.Configuration.SingleTagSectionHandler" />
</configSections>
<device id="1" description="petras room" location="" mall="" />
<server url="http://example.com" />
</configuration>
ConfigurationManager.AppSettings["MyAppSetting"]
只会返回你在配置文件的<appSettings>
下以 "MyAppSetting" 为键名的设置。 - Sameer SinghSingleTagSectionHandler
已经弃用,应该使用ConfigurationSection
代替(链接) - wangkaibule