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

标签 c# iis-6

创建网站后,我注意到它将 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/

相关文章:

c# - Visual Studio 2008编译作品; 2010年编译的同一个项目没有

c# - 应用程序可以在不传递 Application_End 或 Application_Error 的情况下返回 "die"吗?

asp.net - 长时间运行的 HttpWebRequest

c# - 在第一次尝试使用 WCF 失败后,客户端如何尝试重新连接到服务器?

c# - 在 Tpl 中处理异常

c# - 使用 C# 插入到 postgresql 表中

powershell - IIS6 列出应用程序池正在运行的 .net 版本

c# - 是否可以验证 Windows 服务是否正在从另一台计算机运行?

c# - 使用 jQuery 将表单数据发布到 MVC4 Controller 操作方法时出现问题

asp.net - 以编程方式控制输出缓存-根据参数值禁用或启用缓存