使用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装饰?

最佳答案

您不能将configSource=应用于<system.serviceModel>,因为这是配置部分-不是简单的配置部分,并且configSource属性仅在简单的配置部分中可用。

但是,您应该绝对能够将configSource属性应用于<system.serviceModel>内的任何节点-在生产系统中,我一直都这样做-并且它确实可以正常工作。您是否真的尝试过?

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

您能(通过编辑原始问题)向我们展示您的什么吗? serviceModelBehaviors.config看起来像吗?

另外:该文件实际上在Web应用程序的web\config子目录中吗?

关于c# - Web.Config,system.serviceModel的外部文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5162565/

10-13 03:18