I'm having the unfortunate task of migrating several IIS6 servers to IIS8.5. My dry run last week worked pretty well just using web deploy to copy everything over. I had only a few nagging issues that were easily fixed by fixing one or two of the websites. I restored my IIS backup to before I ran web deploy last week, then reran web deploy to copy everything back over like I did last week(due to several new sites being created since last week). To my shock, I ran into all the horrible error messages that are fixed when you revert to parent on the actions page for handler mappings.
Since there's 570 some odd sites and for some crazy reason, it takes 18 seconds to go through the process of selecting a site, selecting handler mappings, clicking revert, answering the question, clicking the next site and it loading. It would take me nearly 3 hours to take care of this server if I didn't pause for even a second.
I'm eternally grateful to have found this topic. I wrote a quick console app to run through and revert to parent on all my sites. I'll take a little over 2 minutes over 2.8 hours any day! I just thought I'd share the full thing in case someone else runs into this issue.
using System;
using System.DirectoryServices;
using System.Collections;
namespace IISHandlerMappingsRevertToParentAll
{
class Program
{
static void Main(string[] args)
{
if (args == null || args.Length != 3)
{
Console.WriteLine("IISHandlerMappingsRevertToParentAll.exe WebServer UserName Password");
Console.WriteLine("Example: IISHandlerMappingsRevertToParentAll WebServer1 WebServer1\\MyUserName MyPassword");
}
else
{
DateTime dt = DateTime.Now;
int cleared = 0;
using (DirectoryEntry root = new DirectoryEntry("IIS://" + args[0] + "/W3SVC", args[1], args[2], AuthenticationTypes.FastBind))
{
foreach (DirectoryEntry r in root.Children)
{
if (r.SchemaClassName == "IIsWebServer")
{
foreach (DirectoryEntry e in r.Children)
{
if (e.SchemaClassName == "IIsWebVirtualDir")
{
ArrayList ScriptMaps = new ArrayList(e.Properties["ScriptMaps"]);
if (ScriptMaps.Count > 0)
{
Console.WriteLine("Clearing for " + e.Properties["Path"].Value);
cleared++;
e.Properties["ScriptMaps"].Clear();
root.CommitChanges();
}
}
}
}
}
}
Console.WriteLine("Reset " + cleared + " took " + DateTime.Now.Subtract(dt).TotalSeconds + "s ");
}
}
}
}