podeig
podeig

Reputation: 2741

How to split web.config?

I want to split web.config and take these settings in a 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="[email protected]">
      <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 standard settings?

Upvotes: 7

Views: 4906

Answers (2)

Andrew Barber
Andrew Barber

Reputation: 40150

Many (though not all) of the sections have a configSource property, which you can use very similarly to how you use the file property of the appSettings section.

More info at MSDN


  <customErrors configSource="MyErrors.config" /> 

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

Upvotes: 9

Mark Redman
Mark Redman

Reputation: 24515

You can separate out some sections of the file, you can't take everything out into separate files.

You should also consider what you gain by doing this.

Upvotes: 0

Related Questions