当前位置首页 > IIS知识

C#设置iis默认文档

阅读次数:257 次  来源:admin  发布时间:
 1 void Main()
 2 {
 3     using (ServerManager serverManager = new ServerManager())
 4     {
 5         var config = serverManager.GetWebConfiguration("SGSM");
 6         ConfigurationSection defaultDocumentSection = config.GetSection("system.webServer/defaultDocument");
 7         defaultDocumentSection["enabled"] = true;
 8         ConfigurationElementCollection filesCollection = defaultDocumentSection.GetCollection("files");
 9         ConfigurationElement addElement = filesCollection.CreateElement("add");
10         addElement["value"] = @"myhome.html";
11         filesCollection.AddAt(0, addElement);
12 
13         serverManager.CommitChanges();
14     }
15 
16     using (ServerManager serverManager = new ServerManager())
17     {
18         var webConfig = serverManager.GetWebConfiguration("SGSM");
19         var section = webConfig.GetSection("system.webServer/defaultDocument");
20 
21         foreach (ConfigurationElement item in section.GetCollection("files"))
22         {
23             var x = item["value"];
24             Console.WriteLine(x);
25         }
26     }
27 }
28 
29 // Define other methods and classes here
上一篇:windows10环境下安装Linux子系统---debian
下一篇:Ubuntu使用wget下载jdk问题