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

Val*_*mas 19 c# configurationmanager app-config web-config

使用VS2010

我在web.config中有以下内容(删除了详细信息).

<system.serviceModel>
    <behaviors />
    <services />
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
    <bindings />
    <client />
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

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

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

The 'configSource' attribute is not allowed
Run Code Online (Sandbox Code Playgroud)

我在这个问题中提到了第二个答案(汤姆兄弟),这个问题展示了我想要的东西.
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> 
Run Code Online (Sandbox Code Playgroud)

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

mar*_*c_s 29

您无法申请configSource=,<system.serviceModel>因为这是一个配置节 - 而不是一个简单的配置节,该configSource属性仅适用于简单的配置节.

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

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

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

另外:该文件是否在物理上位于web\configWeb应用程序的子目录中?

  • 远远看,Visual Studio让我害怕!它确实有效,谢谢. (4认同)
  • 我得到 Visual Studio 2010 告诉我 configSource 对于“system.serviceModel”的“绑定”和“客户端”子元素也是“不允许的”;据我所知,Visual Studio 2010 编辑器是错误的。 (2认同)
  • 我仍然在VS2012上得到这个 (2认同)
  • 仍然在VS2013得到这个. (2认同)