2010-01-30 53 views
1

我們可以從web.config中有以下兩種方式檢索配置部分:通過WebConfigurationManager和配置檢索配置部分對象

Configuration config = WebConfigurationManager.OpenWebConfiguration("/"); 

    AuthenticationSection authSection = (AuthenticationSection) 
      config.GetSection(@"system.web/authentication"); 

OR

AuthenticationSection authSection = (AuthenticationSection)   
     WebConfigurationManager.GetSection(@"system.web/authentication"); 

如何是不同的兩種方法(除事實上,在第一個例子中,我們通過配置對象檢索了一個配置節,它代表了一個配置文件)?

thanx

回答

2

您沒有使用2種不同的方法。如果你仔細看看你的陳述幾乎完全相同。唯一的區別在於,在第二個中,Open語句通過對象隱含並自動化。他們都以同樣的方式做同樣的事情。

+0

我認爲也許有不同從哪個web.config文件的身份驗證部分檢索。在第一種情況下,它從根web.config中檢索,但在第二種情況下,它可能會從其他一些應用程序的Web檢索.config文件(如果存在) – carewithl 2010-01-30 19:48:03

+0

它們都打開當前應用程序的默認web.config(基於現有文件夾),從根開始並搜索system.web/authentication。 – 2010-01-30 19:50:47

+0

thanx幫助我 – carewithl 2010-01-31 18:48:41