【发布时间】:2011-05-27 03:01:29
【问题描述】:
是否可以为 web.config 的特定部分设置单独的配置文件?具体来说,我想将 IIS 7 的重写部分从 web.config 移到它自己的配置文件中。
【问题讨论】:
-
如果您尝试移动 runtime section:runtime section 很乐意接受 configSource 属性,但它不读取外部文件
是否可以为 web.config 的特定部分设置单独的配置文件?具体来说,我想将 IIS 7 的重写部分从 web.config 移到它自己的配置文件中。
【问题讨论】:
您当然可以将重写规则和映射移到单独的文件中:
<system.webServer>
<rewrite>
<rewriteMaps configSource="rewritemaps.config" />
<rules configSource="rewriteRules.config" />
</rewrite>
</system.webServer>
此外,您可以将相当多的配置部分移动到它们自己的文件中:
<appSettings configSource="appSettings.config" />[Docs]
<connectionStrings configSource="connectionStrings.config"/>[Docs]
<pages configSource="pages.config"/>[Docs]
有关更多信息,请参阅此页面,该页面将帮助您确定是否可以将配置部分存储在外部:
【讨论】:
是的,这是可能的。
对于每个配置部分,您可以将configSource 属性设置为您保存配置的位置(文件)。
例如:
<appSettings configSource="appSettings.config" />
在appSettings.config中:
<?xml version="1.0" encoding="UTF-8"?>
<appSettings>
<add key="myKey" value="myValue" />
</appSettings>
【讨论】: