Asp.Net2.0中我們可以方便的訪問設定檔中,.NetFrameWork2.0新增加了 SystemWebSectionGroup 類。
允許使用者以編程方式訪問設定檔的 system.web 組。
比如判斷web.config內是否為 debug="true",或者判斷身分識別驗證形式
SystemWebSectionGroup ws = new SystemWebSectionGroup();
CompilationSection cp = ws.Compilation;
用cp.Debug;就可以得到compilation節內關於"debug"的配置
AuthenticationSection as = ws.Authentication;
用 as.Mode 可以擷取 authentication節中關於"mode"的配置,值為AuthenticationMode 枚舉之一
AuthenticationMode的取值如下:
成員名稱 說明
Forms 將基於 ASP.NET 表單的身分識別驗證指定為身分識別驗證模式。
None 不指定身分識別驗證。
Passport 將 Microsoft Passport 指定為身分識別驗證模式。
Windows 將 Windows 指定為身分識別驗證模式。在使用 Internet 資訊服務 (IIS) 驗證方法(基本、簡要、整合 Windows (NTLM/Kerberos) 或認證)時適用此模式。
附:SystemWebSectionGroup 類的公用屬性:
名稱 說明
AnonymousIdentification 擷取 anonymousIdentification 節。
Authentication 擷取 authentication 節。
Authorization 擷取 authorization 節。
BrowserCaps 擷取 browserCaps 節。
ClientTarget 擷取 clientTarget 節。
Compilation 擷取 compilation 節。
CustomErrors 擷取 customErrors 節。
Deployment 擷取 deployment 節。
DeviceFilters 擷取 deviceFilters 節。
Globalization 擷取 globalization 節。
HealthMonitoring 擷取 healthMonitoring 節。