Web.Config,system.serviceModel的外部文件

时间:2011-03-02 01:48:15

标签: c# web-config app-config configurationmanager

使用VS2010

我的web.config中有以下内容(详细信息已删除)。

<system.serviceModel>
    <behaviors />
    <services />
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
    <bindings />
    <client />
</system.serviceModel>

我想使用属性configSource,就像appSettings可以用来从另一个配置文件中获取这些元素的细节一样。

我尝试将configSource属性应用于system.serviceModel或每个子节点。 但是,我得到了无效的蓝色线条说:

The 'configSource' attribute is not allowed

我在这个问题中提到第二个答案(汤姆兄弟),这个问题展示了我想要的东西 Can a web.config read from an external xml file?

其他
这是该帖子的配置。有无效的蓝色波浪线。

<connectionStrings configSource="web\config\connectionStrings.config" /> 
<appSettings configSource="web\config\appSettings.config" /> 
<system.diagnostics configSource="web\config\diagnostics.config" /> 
<system.serviceModel> 
    <bindings configSource="web\config\serviceModelBindings.config" /> 
    <behaviors configSource="web\config\serviceModelBehaviors.config" /> 
    <services configSource="web\config\serviceModelServices.config" /> 
    <client configSource="web\config\serviceModelClient.config" /> 
</system.serviceModel> 

在这种情况下如何使用configSource属性?

1 个答案:

答案 0 :(得分:29)

您无法将configSource=应用于<system.serviceModel>,因为这是配置部分 - 不是简单的配置部分,configSource属性仅适用于简单的配置部分。

但是,您应该绝对能够将configSource属性应用于<system.serviceModel>中的任何节点 - 我一直在生产系统中这样做 - 它只是起作用。你有没有尝试过?

或者你是否让自己被Visual Studio吓跑了...它可能会告诉你(并告诉你)configSource="...."是不允许的(通过那些波浪下划线) - 但这只是视觉上的一个缺点Studio编辑器 - 在<system.serviceModel>的子节点上, 允许configSource=属性!

您能否告诉我们(通过编辑您的原始问题) serviceModelBehaviors.config看起来像?

另外:该文件是否实际位于Web应用程序的web\config子目录中?