Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I asked this over on Stack Overflow but maybe it's something an experienced IIS 7 administrator might know more about, so I'm asking here as well.

When manipulating Handler Mappings using the Microsoft.Web.Administration namespace, is there a way to remove the <remove name="handler name"> tag added at the site level.

For example, I have a site which inherits all the handler mappings from the global handler mappings configuration. In applicationHost.config the <location> tag initially looks like this:

<location path="60030 - testsite-60030.com">
  <system.webServer>
    <security>
      <authentication>
        <anonymousAuthentication userName="" />
      </authentication>
    </security>
  </system.webServer>
</location>

To remove a handler I use code similar this:

string siteName = "60030 - testsite-60030.com";
string handlerToRemove = "ASPClassic";

using(ServerManager sm = new ServerManager())
{
  Configuration siteConfig = 
    serverManager.GetApplicationHostConfiguration();
  ConfigurationSection handlersSection = 
    siteConfig.GetSection("system.webServer/handlers", siteName);
  ConfigurationElementCollection handlersCollection = 
    handlersSection.GetCollection();

  ConfigurationElement handlerElement = handlersCollection
    .Where(h => h["name"].Equals(handlerMapping.Name)).Single();

  handlersCollection.Remove(handlerElement);
}

The equivalent APPCMD instruction would be:

appcmd set config "60030 - autotest-60030.com" -section:system.webServer/handlers /-[name='ASPClassic'] /commit:apphost

This results in the site's <location> tag looking like:

<location path="60030 - testsite-60030.com">
  <system.webServer>
    <security>
      <authentication>
        <anonymousAuthentication userName="" />
      </authentication>
    </security>    
    <handlers>
      <remove name="ASPClassic" />
    </handlers>
  </system.webServer>
</location>

So far so good. However if I re-add the ASPClassic handler this results in:

<location path="60030 - testsite-60030.com">
  <system.webServer>
    <security>
      <authentication>
        <anonymousAuthentication userName="" />
      </authentication>
    </security>    
    <handlers>
      <!-- Why doesn't <remove> get removed instead of tacking on 
           an <add> directive? -->
      <remove name="ASPClassic" />
      <add name="ASPClassic" path="*.asp" verb="GET,HEAD,POST" modules="IsapiModule" scriptProcessor="%windir%\system32\inetsrv\asp.dll" resourceType="File" />
    </handlers>
  </system.webServer>
</location>

This happens when using both the Microsoft.Web.Administration namespace and C# or using the following APPCMD command:

appcmd set config "60030 - autotest-60030.com" -section:system.webServer/handlers /+[name='ASPClassic',path='*.asp',verb=;'GET,HEAD,POST',modules='IsapiModule',scriptProcessor='%windir%\system32\inetsrv\asp.dll',resourceType='File'] /commit:apphost

This can result in a lot of cruft over time for each website that's had a handler removed then re-added programmatically. Is there a way to just remove the <remove name="ASPClassic" /> tag using the Microsoft.Web.Administration namespace code or APPCMD?

share|improve this question

2 Answers 2

If you add or remove a handler mapping/module manually on a particular site/application/virdir you will get the <remove /> tag added. Now, if you manually add it again the <remove /> tag won't go because as for IIS that means you made some changes in the configuration. This way you it gives you the flexibility to add your own custom mapping or module overriding the global modules/mappings.

Yes, that will produce a lot of clutter but that's the way it's been handled.. at least for now. One way to handle this is click on 'Revert to parent' in the Actions panel.

share|improve this answer
    
Sorry dude, I asked this over on SO as well because it was a bit SO and a bit SF. I got this reply from a MS employee (Tobin Titus), it's a bug: stackoverflow.com/questions/1671702/… –  Kev Mar 22 '10 at 11:40
    
Yes, I know this is a bug. I am an MSFT as well working in IIS & ASP.NET team, and we have come across this issue some time back and the product team is working on this. –  Vivek Kumbhar Mar 22 '10 at 12:43
up vote 0 down vote accepted

I also asked this over on Stack Overflow because the subject matter straddled both sites. This is the answer I got:

How do I manipulate Handler Mappings cleanly in IIS7 using the Microsoft.Web.Administration namespace?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.