如何以编程方式在web.config中更改system.webServer / defaultDocument

时间:2012-10-26 10:32:13

标签: c# asp.net .net asp.net-4.0

我正在尝试访问我的web.config文件中的system.webServer/defaultDocument,但似乎无法找到方法。我已经尝试了各种关于编辑Web配置文件的文章,但我似乎没有相同的选项来访问system.webServer中的项目,就像我在更改connectionString时那样。

我可以使用:

加载system.webServer部分
ConfigurationSection WebServerSection = (ConfigurationSection)WebConfigurationManager.GetSection("system.webServer");

但是从那一点上看不到任何可用的东西。我注意到的一件事是system.webServer部分属于System.Configuration.IgnoreSection类型。这会以某种方式阻止我访问编辑它吗?

1 个答案:

答案 0 :(得分:1)

查看Microsoft.Web.Administration API,它提供WebConfigurationManager class,允许您访问webServer部分的内容:

WebConfigurationManager.GetSection(HttpContext.Current,
  "system.webServer/defaultDocument");
相关问题