How to break web.config?

I want to split web.config and make these settings in an external file.

<customErrors mode="Off" defaultRedirect="~/Home/ErrorPage">
  <error statusCode="403" redirect="~/Home/ErrorPage"/>
  <error statusCode="404" redirect="~/Home/ErrorPage"/>
</customErrors>

<system.net>
  <mailSettings>
    <smtp deliveryMethod="Network" from="noreplay@company.no">
      <network host="smtp.company.com" port="25" password="" userName=""/>
    </smtp>
  </mailSettings>
</system.net>

I use

    <appSettings file="my.config"/> 

to have MY settings outside.

But what about the default settings?

+5
source share
2 answers

Many (though not all) sections have a property configSourcethat you can use very similar to how you use the filesection property appSettings.

Additional Information on MSDN


  <customErrors configSource="MyErrors.config" /> 

  <system.net>
    <mailSettings>
      <smtp configSource="MySmtp.config" />
    </mailSettings>
  </system.net>
+7
source

You can select some sections of a file; you cannot extract everything into separate files.

You should also consider what you get when doing this.

0
source

All Articles