在Asp.Net2.0中可以方便的訪問設定檔web.config,如判斷debug設定,驗證類型等。

來源:互聯網
上載者:User
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 節。
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.