关于web.config
調試模式提供一種特殊的編譯模式,處于調試模式的網站會影響系統的性能.但是,有時候為了便于系統維護,我們會把一些調試時用到的功能模塊集成到產 品網站中,為了不對產品的正常運行造成影響同時又能夠在系統發生故障時方便的使用調試模塊,我想到了好好利用下調試模式.
我們知道,調試模式配置是在web.config文件中的.
<compilation debug="true"> </compilation>
讀取web.config文件需要用到.net 2.0新增加的一些針對配置文件的操作類.
這里用到的是System.Configuration.ConfigurationSettings類,它提供的 GetConfig(string name)方法能夠定位到你要獲取值的結點.
還有一個類,System.Web.Configuration.CompilationSection自然就是定義編譯配置信息的類,這里面有一 個屬性:Debug,它返回一個bool值,以指示當前是否啟用了調試模式.
System.Web.Configuration.CompilationSection ds = (System.Web.Configuration.CompilationSection)System.Configuration.ConfigurationSettings.GetConfig("system.web/compilation"); isDebugEnable = ds.Debug;
上面代碼中用到了一個類型轉換,將獲取到的結點類型轉化為 System.Web.Configuration.CompilationSection類型,從而利用ds.Debug屬性獲得結果.
調試模式時我們可以集成一些有用的功能,這些功能有:
錯誤檢測:檢測系統輸出的錯誤日志并在屏幕上顯示
數據庫查詢檢測:測試數據庫的查詢,并能更改數據庫的部分信息,支持全部的查詢語句并限制查詢的權限
系統日志:在調試模式啟動時,系統將記錄所有的錯誤日志,而不是根據原先的優先級,便于查找Bug.
由于調試模式的啟用必須要到服務器上去配置,因此,安全性上面有了一定的保障,可以確保只有管理員才能夠啟用.
===========================================================================================================
Asp.Net2.0中我們可以方便的訪問配置文件中,.NetFrameWork2.0新增加了 SystemWebSectionGroup 類。
允許用戶以編程方式訪問配置文件的 system.web 組。
比如判斷web.config內是否為 debug="true",或者判斷身份驗證形式
System.Configuration.Configuration configuration = WebConfigurationManager..OpenWebConfiguration("");)
//配置文件的虛擬目錄,如果null則取根目錄下的web.config
SystemWebSectionGroup ws = (SystemWebSectionGroup)configuration.GetSectionGroup("system.web");
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 節
轉載于:https://www.cnblogs.com/zhangji/archive/2011/04/21/2023203.html
總結
以上是生活随笔為你收集整理的关于web.config的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ZOJ 1161 Gone Fishin
- 下一篇: Javascript 用本页面文本域中的