1

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.

Thanks!

1 Answer 1

2

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:

http://www.iis.net/ConfigReference/system.webServer/handlers

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', path='*.mything',modules='MyApp.MyHandler',preCondition='integratedMode', resourceType='Unspecified',verb='GET,HEAD,POST']" /commit:apphost 

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.

2
  • 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! Commented Jun 29, 2011 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 :) Commented Jun 29, 2011 at 21:20

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.