23

使用VS2010

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

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

我想使用与 appSettings 相同的属性 configSource 从另一个配置文件中获取这些元素的详细信息。

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

The 'configSource' attribute is not allowed

我在这个问题中提到了第二个答案(汤姆兄弟),它证明了我想要什么。
web.config 可以从外部 xml 文件中读取吗?

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

<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 属性?

4

1 回答 1

34

您不能申请configSource=<system.serviceModel>因为这是一个配置部分- 不是一个简单的配置部分,并且该configSource属性仅适用于简单的配置部分。

但是,您绝对应该能够将 configSource 属性应用于内部的任何节点<system.serviceModel> ——我一直在生产系统中这样做——而且它确实有效。你真的试过了吗??

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

你能告诉我们(通过编辑你原来的问题)你的例子是什么serviceModelBehaviors.config样的吗?

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

于 2011-03-02T06:03:03.927 回答