34

我可以创建 .config 文件并将其包含到 web.config 中吗?我怎样才能做到这一点?

UPD。如果你想分离配置文件,例如,将 appSettings 移动到另一个文件,你必须下一步:在 web.config

  <appSettings configSource="myAppSettings.config" />

在 myAppSettings.config 中:

  <appSettings>
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
4

2 回答 2

32

尚不完全清楚您要做什么,但所有配置部分都可以存储在单独的文件中,并由.config使用configSource属性的主文件引用。

有关详细信息,请参阅博客文章。

于 2012-04-24T14:32:40.230 回答
24

这是将多个配置集成到一个 web.config 中的方法

web.config 中的代码:

<appSettings configSource="config\appSettings.config"/>
<nlog configSource="config\nlog.config"/>
<applicationSettings>
        <MyApp.UI.Properties.Settings configSource="config\Settings.APGUI.config"/>
        <MyApp.BusinessServices.Properties.Settings configSource="config\Settings.Business.config"/>
        <MyApp.Auditing.Properties.Settings configSource="config\Settings.Auditing.config"/>
</applicationSettings>

更多:在部署环境之间管理复杂的 Web.Config 文件

于 2012-04-24T14:34:17.247 回答