为web.config的各个部分分隔配置文件

Cod*_*313 28 asp.net iis-7

是否可以为web.config的特定部分分别配置文件?具体来说,我想将IIS 7的重写部分移出web.config并进入它自己的配置文件.

Kev*_*Kev 41

您当然可以将重写规则和映射移到单独的文件中:

将URL重写映射存储在单独的文件中

<system.webServer>
  <rewrite>
    <rewriteMaps configSource="rewritemaps.config" />
    <rules configSource="rewriteRules.config" />
  </rewrite>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

此外,您可以将相当多的配置部分移动到自己的文件中:

<appSettings configSource="appSettings.config" /> [Docs]

<connectionStrings configSource="connectionStrings.config"/> [Docs]

<pages configSource="pages.config"/> [Docs]

有关详细信息,请参阅此页面,该页面将帮助您确定是否可以在外部存储配置部分:

由Section Elements继承的常规属性

  • **运行时部分**愉快地接受了 configSource 属性,但它***不读取外部文件*** (2认同)

Ode*_*ded 19

是的,这是可能的.

对于每个配置节,您可以将configSource属性设置为您保存配置的位置(文件).

例如:

<appSettings configSource="appSettings.config" />
Run Code Online (Sandbox Code Playgroud)

appSettings.config中:

<?xml version="1.0" encoding="UTF-8"?>
<appSettings>
    <add key="myKey" value="myValue" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)