朱丽叶的回答是正确的,但仅供参考,您还可以通过如下.config
设置将其他配置放入外部文件中:web.config
<?xml version="1.0"?>
<configuration>
<configSections>
<!-- blah blah the default stuff here -->
<!-- here, add your custom section -->
<section name="DocTabMap" type="System.Configuration.NameValueFileSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<!-- your custom section, but referenced in another file -->
<DocTabMap file="CustomDocTabs.config" />
<!-- etc, remainder of default web.config is here -->
</configuration>
然后,你的CustomDocTabs.config
样子是这样的:
<?xml version="1.0"?>
<DocTabMap>
<add key="A" value="1" />
<add key="B" value="2" />
<add key="C" value="3" />
<add key="D" value="4" />
</DocTabMap>
现在您可以通过以下方式在代码中访问它:
NameValueCollection DocTabMap = ConfigurationManager.GetSection("DocTabMap") as NameValueCollection;
DocTabMap["A"] // == "B"