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 类的公共属性:
  名称 说明
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 AnonymousIdentification 获取 anonymousIdentification 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 Authentication 获取 authentication 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 Authorization 获取 authorization 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 BrowserCaps 获取 browserCaps 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 ClientTarget 获取 clientTarget 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 Compilation 获取 compilation 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 CustomErrors 获取 customErrors 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 Deployment 获取 deployment 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 DeviceFilters 获取 deviceFilters 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 Globalization 获取 globalization 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 HealthMonitoring 获取 healthMonitoring 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 HostingEnvironment 获取 hostingEnvironment 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 HttpCookies 获取 httpCookies 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 HttpHandlers 获取 httpHandlers 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 HttpModules 获取 httpModules 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 HttpRuntime 获取 httpRuntime 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 Identity 获取 identity 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 IsDeclarationRequired  获取一个值,该值指示是否需要声明此 ConfigurationSectionGroup 对象。 (从 ConfigurationSectionGroup 继承。)
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 IsDeclared  获取一个值,该值指示是否已声明此 ConfigurationSectionGroup 对象。(从 ConfigurationSectionGroup 继承。)
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 MachineKey 获取 machineKey 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 Membership 获取 membership 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 MobileControls 获取 mobileControls 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 Name  获取此 ConfigurationSectionGroup 对象的名称属性。(从 ConfigurationSectionGroup 继承。)
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 Pages 获取 pages 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 ProcessModel 获取 processModel 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 Profile 获取 profile 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 Protocols 获取 protocols 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 RoleManager 获取 roleManager 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 SectionGroupName  获取与此 ConfigurationSectionGroup 关联的节组名称。(从 ConfigurationSectionGroup 继承。)
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 SectionGroups  获取一个包含所有 ConfigurationSectionGroup 对象的 ConfigurationSectionGroup 对象,这些对象是此 ConfigurationSectionGroup 对象的子对象。(从 ConfigurationSectionGroup 继承。)
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 Sections  获取一个 ConfigurationSectionCollection,它包含此 ConfigurationSectionGroup 中的所有 ConfigurationSection 对象。(从 ConfigurationSectionGroup 继承。)
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 SecurityPolicy 获取 securityPolicy 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 SessionState 获取 sessionState 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 SiteMap 获取 siteMap 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 Trace 获取 trace 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 Trust 获取 trust 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 Type  获取或设置此 ConfigurationSectionGroup 对象的类型。(从 ConfigurationSectionGroup 继承。)
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 UrlMappings 获取 urlMappings 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 WebControls 获取 webControls 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 WebParts 获取 webParts 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 WebServices 获取 webServices 节。
在Asp.Net2.0中可以方便的访问配置文件web.config,如判断debug设置,验证类型等。 XhtmlConformance 获取 xhtmlConformance 节。

相关文章: