【问题标题】:Can I create .config file and include it to web.config?我可以创建 .config 文件并将其包含到 web.config 中吗?
【发布时间】:2012-04-24 14:30:18
【问题描述】:

我可以创建 .config 文件并将其包含到 web.config 中吗? 我该怎么做?

UPD。 如果你想分离配置文件,例如,将 appSettings 移动到另一个文件,你必须下一步:在 web.config 中

  <appSettings configSource="myAppSettings.config" />

在 myAppSettings.config 中:

  <appSettings>
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>

【问题讨论】:

  • 可以部分做吗?我的意思是一些设置属于 web.config 而一些来自其他配置文件?

标签: asp.net config


【解决方案1】:

您想要做什么并不完全清楚,但所有配置部分都可以存储在单独的文件中,并由主.config 文件使用configSource 属性引用。

详情请参阅this 博文。

【讨论】:

    【解决方案2】:

    这是将多个配置集成到一个 web.config 中的方式

    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>
    

    更多:Managing complex Web.Config files between deployment environments

    【讨论】:

    • 这种方法的问题是,我经常希望能够在一个文件中拥有一些应用程序设置,而在另一个文件中拥有一些应用程序设置,这在使用configSource 时是不可能的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    • 1970-01-01
    • 2016-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多