首页 > Windows开发 > 详细

C# 增加 IIS 默认主页文档

时间:2020-11-10 14:08:54      阅读:35      评论:0      收藏:0      [点我收藏+]
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 默认主页文档

原文:https://www.cnblogs.com/nanfei/p/13953288.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!