34

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

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

  <appSettings configSource="myAppSettings.config" />

In myAppSettings.config:

  <appSettings>
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
Roman Bats
  • 1,775
  • 3
  • 30
  • 40
  • 3
    Is it possible to do partially? I mean some settings belong to web.config whereas some from other config file? – Hiren Desai Nov 10 '16 at 06:24

2 Answers2

32

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.

See this blog post for details.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
24

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

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

Community
  • 1
  • 1
HW90
  • 1,953
  • 2
  • 21
  • 45
  • 4
    The problem with this approach is that often I want to be able have some app settings in one file and some app settings in another file, which isn't possible when using `configSource`. – Rudey Oct 19 '18 at 20:27