创建网站后,我注意到它将 asp.net 版本设置为 1.1。我想在代码中将其更改为版本 2.0.50727。我发现在 ScriptMaps 属性中有所有文件扩展名和代码映射的字符串列表。但我还没有弄清楚如何更改连接到 .net 的所有值?或者有没有办法告诉它使用其他版本的 .invoke?
最佳答案
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();
经过一番尝试和错误,我找到了解决方案。我获取了创建的站点中的所有对象,并制作了一个副本,在其中更改了路径字符串的版本部分。然后我将 scriptMaps 对象的 value 属性设置为指向新更新的对象数组。
关于c# - IIS 6.0 DirectoryEntry ScriptMaps 属性并设置.Net 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1299084/