【问题标题】:Inserting multiple items with Web.Config transforms使用 Web.Config 转换插入多个项目
【发布时间】:2012-09-30 07:54:14
【问题描述】:

我有一个 C# 项目,它引用了很多 WCF 服务。对于本地测试,我想替换身份标签的内容,以便它接受在 localhost 上运行的任何内容。

以下转换有效,但仅在第一个匹配位置插入 dns 元素。因此,如果我引用了 5 个端点,其中一个将具有 dns 标记,而其他端点将具有空标识元素。

<system.serviceModel>
    <client>
      <endpoint>
        <identity>
          <dns xdt:Transform="Insert" value="localhost"/>
          <userPrincipalName xdt:Transform="RemoveAll" value="someIdentity" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

如何更改所有匹配的元素,而不仅仅是第一个?

【问题讨论】:

  • 您是否要删除所有&lt;userPrincipalName&gt; 元素?
  • 是的,那部分工作正常。但是,我也想用 替换那些 元素,但我没有这样做。我已经通过手动列出所有端点来解决这个问题,但是如果有更优雅的解决方案,我很想听听。

标签: asp.net web-config web-config-transform


【解决方案1】:

使用xdt:Locator 属性定义XPath 表达式以匹配您要插入的所有&lt;identity&gt; 元素。

  <system.serviceModel>
    <client>
      <endpoint>
        <identity xdt:Locator="XPath(//identity)">
          <dns xdt:Transform="Insert" value="localhost"/>
          <userPrincipalName xdt:Transform="RemoveAll"/>
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-09
  • 2014-08-25
  • 1970-01-01
  • 2018-12-19
  • 1970-01-01
相关资源
最近更新 更多