Inserting multiple items with Web.Config transforms

被刻印的时光 ゝ 提交于 2019-12-01 02:52:39

问题


I've got a C# project that references a lot of WCF services. For local testing, I want to replace the contents of the identity tags so that it will accept anything running on localhost.

The following transformation works, but only inserts the dns element in the first matching location. So, if I had 5 endpoints referenced, one would have the dns tag, and the others would all have empty identity elements.

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

How do I alter all of the matching elements, not just the first?


回答1:


Use the xdt:Locator attribute to define an XPath expression to match all <identity> elements that you want to insert into.

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


来源:https://stackoverflow.com/questions/12809264/inserting-multiple-items-with-web-config-transforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!