如何拆分web.config?

时间:2012-09-05 11:05:41

标签: c# web-config

我想拆分web.config并将这些设置放在外部文件中。

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

我用

    <appSettings file="my.config"/> 

将我的设置放在外面。

但标准设置怎​​么样?

2 个答案:

答案 0 :(得分:9)

许多(尽管不是全部)部分都有configSource属性,您可以使用与file部分的appSettings属性非常相似的方式。

More info at MSDN


  <customErrors configSource="MyErrors.config" /> 

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

答案 1 :(得分:0)

您可以将文件的某些部分分开,但不能将所有内容整理到单独的文件中。

你也应该考虑通过这样做获得什么。

相关问题