简体   繁体   中英

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

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

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

预览截图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM