代码之家  ›  专栏  ›  技术社区  ›  Ahmy

如何使用c_在IIS中以编程方式更改默认文档顺序?

  •  2
  • Ahmy  · 技术社区  · 15 年前

    我有一个ASP.NET网站应用程序,我的网站有一个主页。我需要能够以编程方式(c)更改我的网站的默认文档,以便使另一个网页优先于已经存在的网页。然后我想恢复到以前的默认文档顺序。

    例子:

    我有两个主页- Home1.aspx Home2.aspx . 在IIS默认文档设置中,我添加了两个页面并 Adv1.ASPX 然后成为第一个默认文档 HEMA2.ASPX 第二。在某些情况下,我需要能够更改两个默认文档的顺序,以便 HEMA2.ASPX 是第一个默认文档吗? Adv1.ASPX 第二。

    我怎样才能从我的C代码中做到这一点?

    事先谢谢你的回复

    3 回复  |  直到 14 年前
        1
  •  3
  •   erlando    15 年前

    此简单示例演示如何更改默认文档顺序:

    using System.DirectoryServices;
    
    class Program
    {
        static void Main(string[] args)
        {
            // You need to change this value to match your site ID in IIS.
            int iisNumber = 668;  
    
            /* If your site is in its own IIS application/vdir under the site root
               and you've touched the default document settings or only want the 
               default document altered for that application/vdir folder then 
               specify as:
    
               IIS://Localhost/W3SVC/{0}/root/MyApplication
            */
            string metabasePath = 
                   String.Format("IIS://Localhost/W3SVC/{0}/root", iisNumber);
            //Change one way
            using (DirectoryEntry de = new DirectoryEntry(metabasePath))
            {
                de.Properties["DefaultDoc"].Value = "Home1.aspx,Home2.aspx";
                de.CommitChanges();
            }
    
            // Change back
            using (DirectoryEntry de = new DirectoryEntry(metabasePath))
            {
                de.Properties["DefaultDoc"].Value = "Home2.aspx,Home1.aspx";
                de.CommitChanges();
            }
        }
    }
    

    这将在运行IIS 6管理兼容性位的IIS 6和IIS 7上工作。

        2
  •  1
  •   Stephen Wrighton    15 年前

    一种可能是有一个默认的或主页,它决定(根据请求)是否应该将用户发送到home1或home2。

        3
  •  1
  •   AaronS    15 年前

    This Article 演示如何在C_中修改IIS元数据库以执行所需操作。

    您必须枚举所有属性才能找到所需的属性。 This article 会帮你的。