IIS 6.0 DirectoryEntry ScriptMaps属性并设置.Net版本

Gao*_*ter 2 c# iis-6

创建一个网站后,我注意到它将asp.net版本设置为1.1.我想在代码中将此更改为版本2.0.50727.我发现在ScriptMaps属性中有所有文件扩展名和代码映射的字符串列表.但我还没想出如何更改连接到.net的所有值?或者有没有办法告诉它使用.invoke的其他verison?

Gao*_*ter 5

DirectoryEntry sited = new DirectoryEntry(string.Format("IIS://localhost/w3svc/{0}/Root", websiteID.ToString()));
sited.Properties["AccessRead"].Add(true);

PropertyValueCollection testScriptMap = sited.Properties["ScriptMaps"];

object[] allValues = (object[])testScriptMap.Value;
object[] newValues = new object[allValues.Length];
string oldVersion = "v1.1.4322";
string newVersion = "v2.0.50727";
for (int i = 0; i < allValues.Length; i++)
{
    if (allValues[i] is string)
    {
        string temp = allValues[i] as string;
        if (temp.Contains(oldVersion))
        {
            newValues[i] = temp.Replace(oldVersion, newVersion);
        }
        else
        {
            newValues[i] = allValues[i];
        }
    }
    else
    {
        newValues[i] = allValues[i];
    }
}
testScriptMap.Value = newValues;            

sited.CommitChanges();
Run Code Online (Sandbox Code Playgroud)

经过一些试验和错误,我找到了解决方案.我获取了创建的站点中的所有对象并制作了一个副本,我在其中更改了路径字符串的版本部分.然后我将scriptMaps对象的value属性设置为指向新更新的对象数组.