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 節。 |
|
HostingEnvironment |
擷取 hostingEnvironment 節。 |
|
HttpCookies |
擷取 httpCookies 節。 |
|
HttpHandlers |
擷取 httpHandlers 節。 |
|
HttpModules |
擷取 httpModules 節。 |
|
HttpRuntime |
擷取 httpRuntime 節。 |
|
Identity |
擷取 identity 節。 |
|
IsDeclarationRequired |
擷取一個值,該值指示是否需要聲明此 ConfigurationSectionGroup 對象。 (從 ConfigurationSectionGroup 繼承。) |
|
IsDeclared |
擷取一個值,該值指示是否已聲明此 ConfigurationSectionGroup 對象。(從 ConfigurationSectionGroup 繼承。) |
|
MachineKey |
擷取 machineKey 節。 |
|
Membership |
擷取 membership 節。 |
|
MobileControls |
擷取 mobileControls 節。 |
|
Name |
擷取此 ConfigurationSectionGroup 對象的名稱屬性。(從 ConfigurationSectionGroup 繼承。) |
|
Pages |
擷取 pages 節。 |
|
ProcessModel |
擷取 processModel 節。 |
|
Profile |
擷取 profile 節。 |
|
Protocols |
擷取 protocols 節。 |
|
RoleManager |
擷取 roleManager 節。 |
|
SectionGroupName |
擷取與此 ConfigurationSectionGroup 關聯的節組名稱。(從 ConfigurationSectionGroup 繼承。) |
|
SectionGroups |
擷取一個包含所有 ConfigurationSectionGroup 對象的 ConfigurationSectionGroup 對象,這些對象是此 ConfigurationSectionGroup 對象的子物件。(從 ConfigurationSectionGroup 繼承。) |
|
Sections |
擷取一個 ConfigurationSectionCollection,它包含此 ConfigurationSectionGroup 中的所有 ConfigurationSection 對象。(從 ConfigurationSectionGroup 繼承。) |
|
SecurityPolicy |
擷取 securityPolicy 節。 |
|
SessionState |
擷取 sessionState 節。 |
|
SiteMap |
擷取 siteMap 節。 |
|
Trace |
擷取 trace 節。 |
|
Trust |
擷取 trust 節。 |
|
Type |
擷取或設定此 ConfigurationSectionGroup 對象的類型。(從 ConfigurationSectionGroup 繼承。) |
|
UrlMappings |
擷取 urlMappings 節。 |
|
WebControls |
擷取 webControls 節。 |
|
WebParts |
擷取 webParts 節。 |
|
WebServices |
擷取 webServices 節。 |
|
XhtmlConformance |
擷取 xhtmlConformance 節。 |