当前位置首页 > IIS知识

C#增加IIS默认主页文档

阅读次数:276 次  来源:admin  发布时间:
void Main()
{
    using (ServerManager serverManager = new ServerManager())
    {
        var config = serverManager.GetWebConfiguration("SGSM");
        ConfigurationSection defaultDocumentSection = config.GetSection("system.webServer/defaultDocument");
        defaultDocumentSection["enabled"] = true;
        ConfigurationElementCollection filesCollection = defaultDocumentSection.GetCollection("files");
        ConfigurationElement addElement = filesCollection.CreateElement("add");
        addElement["value"] = @"myhome.html";
        filesCollection.AddAt(0, addElement);

        serverManager.CommitChanges();
    }

    using (ServerManager serverManager = new ServerManager())
    {
        var webConfig = serverManager.GetWebConfiguration("SGSM");
        var section = webConfig.GetSection("system.webServer/defaultDocument");

        foreach (ConfigurationElement item in section.GetCollection("files"))
        {
            var x = item["value"];
            Console.WriteLine(x);
        }
    }
}

// Define other methods and classes here
上一篇:IIRF(IonicsIsapiRewriteFilter)实现在IIS5/6上重写Url
下一篇:Fedora14源码安装qt4.7.0PC版和arm版过程及问题解决(之二,续上)