Creating Sites in IIS 6.0 And Automatically Switching Them to use the 2.0 Framework in c#
So, you’ve got the code in place to create a site in IIS via c# in one of your web apps, but you want the site ASP.NET version to default to 2.0. I had the problem and couldn’t find a simple “switch” to flip, so I wound up writing this little piece of code that goes in and manually remaps the files that need it, from the 1.1 framework to the 2.0. After that runs, your IIS ASP.NET version will read 2.0, and act accordingly
ManagementObjectSearcher searcher = new ManagementObjectSearcher(@”root\MicrosoftIISv2″,
“SELECT * FROM IIsWebVirtualDirSetting WHERE Path = ‘” + pathToRoot.Replace(@”\”, @”\\”) + webSiteName + “‘”);
foreach (ManagementObject queryObj in searcher.Get())
{
if (queryObj.Properties["ScriptMaps"] != null)
{
Object[] arrScriptMaps = (Object[])(queryObj["ScriptMaps"]);
foreach (Object arrValue in arrScriptMaps)
{
foreach (PropertyData data in ((ManagementBaseObject)arrValue).Properties)
{
if (Convert.ToString(data.Value).ToLower() == @”c:\windows\microsoft.net\framework\v1.1.4322\aspnet_isapi.dll”)
if (data.Name == “ScriptProcessor”)
data.Value = @”c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll”;
}
}
queryObj.SetPropertyValue(“ScriptMaps”, arrScriptMaps);
queryObj.Put();
}
}
Recent Comments