加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 使用Web.Config转换插入多个项目

发布时间:2020-12-16 03:48:28 所属栏目:asp.Net 来源:网络整理
导读:我有一个引用了很多WCF服务的C#项目.对于本地测试,我想替换身份标记的内容,以便它接受在localhost上运行的任何内容. 以下转换有效,但仅在第一个匹配位置插入dns元素.因此,如果我引用了5个端点,则会有一个dns标记,而其他端点都会有空的标识元素. system.servi
我有一个引用了很多WCF服务的C#项目.对于本地测试,我想替换身份标记的内容,以便它接受在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>

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

解决方法

使用xdt:Locator属性定义XPath表达式以匹配所有< identity>要插入的元素.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读