How to remove a Module in web.config with config transform

4.4k views Asked by At

I've got a section of my web.config that looks like the following:

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
    <remove name="WebDAVModule" />
    <add name="ImageResizingModule" type="ImageResizer.InterceptModule" />
    <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
    <add name="Prerender" type="Prerender.io.PrerenderModule, Prerender.io, Version=1.0.0.2, Culture=neutral, PublicKeyToken=null" />
</modules>

I want to just get rid of the line

I've tried this but it gets rid of all but WebDav

<system.webServer>
<rewrite xdt:Transform="Replace">
  <rules>
  </rules>
</rewrite>
<modules runAllManagedModulesForAllRequests="true">
  <add name="Prerender" type="Prerender.io.PrerenderModule, Prerender.io, Version=1.0.0.2, Culture=neutral, PublicKeyToken=null" 
       xdt:Transform="RemoveAll" />
</modules

1

There are 1 answers

0
hutchonoid On

You can use a combination of xdt:Transform="Remove" and xdt:Locator="Match(name)" as follows:

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="WebDAVModule" />
      <add name="ImageResizingModule" type="ImageResizer.InterceptModule" xdt:Transform="Remove" xdt:Locator="Match(name)" />
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
      <add name="Prerender" type="Prerender.io.PrerenderModule, Prerender.io, Version=1.0.0.2, Culture=neutral, PublicKeyToken=null" />
    </modules>
  </system.webServer>

The above will remove the module that matches by name in this case ImageResizingModule.

Screen shot of the preview

Screen shot of preview