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

Rom*_*ats 31 asp.net config

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

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

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

在myAppSettings.config中:

  <appSettings>
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
Run Code Online (Sandbox Code Playgroud)

Ode*_*ded 29

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

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


HW9*_*W90 21

这是将多个配置集成到一个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>
Run Code Online (Sandbox Code Playgroud)

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

  • 这种方法的问题是,我经常希望能够在一个文件中拥有一些应用程序设置,而在另一个文件中拥有一些应用程序设置,而在使用`configSource`时是不可能的。 (4认同)