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

1.5k views Asked by At

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.

2

There are 2 answers

1
jrummell On

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"/>
0
Alastair On

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.