How would I remove Elmah modules from web.config using XML-Document-Transform?

ε祈祈猫儿з 提交于 2019-12-24 10:23:22

问题


In other words, in the following web.config xml, I want to remove all elements with a type attribute that starts with 'Elmah.'

<httpModules>
  <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
  <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
  <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules>

I have tried several combinations and structures of the basic transform, with various errors,

<add xdt:Locator="XPath([starts-with(@type,'Elmah.')" xdt:Transform="Remove"/>

before giving up and just removing the whole httpModules element, because no XPath is needed for that.


回答1:


The XPath Locator expects a fully qualified XPath location, so your transform is not currently matching any elements. If you use the Condition Locator (which expects a relative XPath) instead, it should match:

<add xdt:Locator="Condition(starts-with(@type,'Elmah.')" xdt:Transform="RemoveAll"/>

Note also that the xdt:Transform Remove will only operate on the first matched element, so you need to use RemoveAll to achieve what you want.

The summary on msdn covers this quite well.




回答2:


Have you tried removing each module individually?

<add name="ErrorLog" xdt:Locator="Match(name)" xdt:Transform="Remove"/>
<add name="ErrorMail" xdt:Locator="Match(name)" xdt:Transform="Remove"/>
<add name="ErrorFilter" xdt:Locator="Match(name)" xdt:Transform="Remove"/>


来源:https://stackoverflow.com/questions/12166618/how-would-i-remove-elmah-modules-from-web-config-using-xml-document-transform

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