【问题标题】:Web.Config, external file for system.serviceModelWeb.Config,system.serviceModel 的外部文件
【发布时间】:2011-07-06 23:04:49
【问题描述】:

使用 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

我指的是这个问题中的第二个答案(汤姆兄弟),它展示了我想要什么。
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 应用到底层节点的?您能否将其包含在内,以便我们查看生成错误的配置文件?
  • @David Hoerster:我也没有成功(应用于底层节点)。链接的文章建议它,虽然我不能让它工作。我已经调整了我的帖子以显示该帖子的答案。
  • 是的,这确实是 Visual Studio 的失败。因此,如果您使用它,您将不得不忍受 VS 中的永久警告。

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


【解决方案1】:

您不能将configSource= 应用于&lt;system.serviceModel&gt;,因为这是一个配置部分组 - 不是一个简单的配置部分,configSource 属性仅适用于简单的配置部分。

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

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

你能告诉我们(通过编辑你原来的问题)你的例如什么吗? serviceModelBehaviors.config 看起来像??

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

【讨论】:

  • 我得到 Visual Studio 2010 告诉我,对于 bindings 和 client 的 system.serviceModel 的子元素,configSource 也是“不允许的”;据我所知,Visual Studio 2010 编辑器是错误的。
  • 我仍然在 VS2012 上得到这个
  • 在 VS2013 中仍然得到这个。
  • 刚刚签入VS2013。
  • VS2015 中的相同警告。去微软吧!
猜你喜欢
  • 2012-05-30
  • 2010-11-20
  • 1970-01-01
  • 2012-07-31
  • 2013-09-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-09
相关资源
最近更新 更多