We have a bunch of sites running with about 8 handler mappings in their web.config files. Unfortunately, they were getting copied site to site every time a new one was added.

Now the time has come for me to get these out of all the web.config's and get them into the server's Handler Mappings.

If I add the mapping to the the server while it still exists in the web.config, IIS throws an error when you browse to the site. I have a few dozen web.config's to edit here with about 10 mappings in each.

Is there a way to add these mappings to the server without having to go in an edit each web.config file manually? Otherwise, every site will be down for a few minutes while I go into each file and remove the handlers.


migrated from webmasters.stackexchange.com Jun 29 '11 at 20:20

This question came from our site for pro webmasters.


You really have no choice other here if you're doing this manually. Even if you did just one handler mapping at a time via the UI you're either going to have to have both the site and the global handler installed at the same time (albeit briefly) or remove the local site one then re-add to the global settings.

You could of course script this using appcmd.exe:


For example:

To remove a handler from a site (I'm using the Default Web Site as an example) -

appcmd set config "Default Web Site" -section:system.webServer/handlers /-"[name='MyHandler']"

To add a handler to the global or "APP HOST" config:

appcmd set config -section:system.webServer/handlers /+"[name='MyHandler',

I've split the above command over four lines just to make it readable, it should in fact be just one line.

Using a script would mean your interruption time would be around a minute rather than several.

  • Yikes, it seems like it would do the trick. I'm a little shaky in the command prompt because I'm afraid if I hose something up, it will take longer to recover. I'm going to mark this answered because this will definitely satisfy my problem. I think I might do this by hand :\ Thanks! – Danomite Jun 29 '11 at 21:17
  • 1
    When I do these larger batch updates I usually do a trial run on a test server. But to be honest, if you have your web.config files backed up and have applicationHost.config open you can quickly edit and roll back. I usually practice these types of things a few times :) – Kev Jun 29 '11 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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