Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split web.config?

Tags:

c#

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?

like image 866
podeig Avatar asked Sep 05 '12 11:09

podeig


People also ask

Can we have 2 web config?

Yes you can have two web. config files in application. There are situations where your application is divided in to modules and for every module you need separate configuration. For example if you have a application which has two modules lets say accounts and sales.


1 Answers

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>
like image 179
Andrew Barber Avatar answered Sep 20 '22 14:09

Andrew Barber