我可以创建.config文件并将其包含到web.config中吗?

时间:2021-10-13 20:18:54

Can I create .config file and include it to web.config? How can i do this?

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

UPD. If you want to separate config file, for example, move appSettings to another file you must do next: In web.config

UPD。例如,如果要分离配置文件,请将appSettings移动到下一步必须执行的另一个文件:在web.config中

  <appSettings configSource="myAppSettings.config" />

In myAppSettings.config:

在myAppSettings.config中:

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

2 个解决方案

#1


24  

It is not entirely clear what you want to do, but all configuration sections can be stored in a separate files and be referenced by the main .config file using the configSource property.

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

See this blog post for details.

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

#2


19  

This is the way to integrate multiple configs into one web.config

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

Code in 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>

more: Managing complex Web.Config files between deployment environments

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

#1


24  

It is not entirely clear what you want to do, but all configuration sections can be stored in a separate files and be referenced by the main .config file using the configSource property.

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

See this blog post for details.

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

#2


19  

This is the way to integrate multiple configs into one web.config

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

Code in 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>

more: Managing complex Web.Config files between deployment environments

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