2012-10-26 91 views
0

我想在我的web.config文件中訪問system.webServer/defaultDocument,但似乎無法找到如何。我已經嘗試了各種關於編輯Web配置文件的文章,但我似乎沒有相同的選項來訪問system.webServer中的項目,就像我更改connectionString時一樣。如何以編程方式更改web.config中的system.webServer/defaultDocument

我可以使用加載system.webServer部分:

ConfigurationSection WebServerSection = (ConfigurationSection)WebConfigurationManager.GetSection("system.webServer"); 

,但不能看到找到任何東西從該點可使用。我注意到的一件事是system.webServer部分的類型是System.Configuration.IgnoreSection。這是否阻止我有權編輯它?

回答

1

我們來看一看Microsoft.Web.Administration API,它提供了一個WebConfigurationManager class應該可以訪問的網絡服務器部分的內容:

WebConfigurationManager.GetSection(HttpContext.Current, 
    "system.webServer/defaultDocument"); 
+0

我似乎無法找到Microsoft.Web.Administration命名空間中使用我的網站。它位於哪裏? – webnoob

+0

沒關係,我在'%windir%\ syswow64 \ inetsrv'中發現它。我也在看這篇文章,它似乎與此DLL一致。 http://blogs.msdn.com/b/saurabh_singh/archive/2007/11/24/accessing-iis-7-0-features-programmatically-from-configuration-file-s-c.aspx謝謝。 – webnoob

相關問題