我如何检查是否调试在web.config中启用 [英] How do I check if Debug is enabled in web.config
问题描述
我从VB.NET1.1天,让我来动态检查,如果调试是在web.config中启用一些code。我想,为什么重新发明的打开/关闭日志记录的车轮,如果我可以简单地在网络管理员启用调试。这里是code我在VB.NET中使用的工作就好了:
I have some code from my VB.NET 1.1 days that allowed me to dynamically check if Debug was enabled in web.config. I figured why re-invent the wheel in turning on/off logging if I could simply have the web administrator enable debug. Here is the code I used in VB.NET that worked just fine:
ConfigurationSettings.GetConfig("system.web/compilation").Debug.ToString()
当我想将其转换为C#和使用.NET 3.5我遇到了一些麻烦,这是行不通的。此外,我想用ConfigurationManager.GetSection的新结构。任何人都可以提出如何更好地阅读的System.Web /编译/调试=真?| false值
When I wanted to convert this to C# and use it in .NET 3.5 I ran into some trouble and it wouldn't work. Additionally, I would like to use the newer construct of ConfigurationManager.GetSection. Can anyone suggest how best to read the system.web/compilation/debug=true|false value?
大部分AP preciated!
Much appreciated!
推荐答案
使用:
HttpContext.Current.IsDebuggingEnabled
此属性实际上着眼于web.config配置设置。如果你看一下使用反射它,你会发现它使用一些内部类得到实际的ConfigurationSection对象。
This property actually looks at the web.config configuration setting. If you look at it using Reflector you will find that it gets the actual ConfigurationSection object using some internal classes.
这篇关于我如何检查是否调试在web.config中启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!