C# 增加 IIS 默认主页文档

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

 

C# 增加 IIS 默认主页文档

上一篇:C# out和ref的用法与区别


下一篇:AcWing 167 木棒 (搜索 + 剪枝)