如何在web.config中检查Debug是否启用 [英] How do I check if Debug is enabled in web.config

查看:129
本文介绍了如何在web.config中检查Debug是否启用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些VB.NET 1.1的代码,让我动态地检查在web.config中是否启用了Debug。我想,如果我可以简单地让网络管理员启用调试,为什么要重新发明车轮打开/关闭日志记录。这是VB.NET中使用的代码,工作正常:

  ConfigurationSettings.GetConfig(system.web / compilation ).Debug.ToString()

当我想将其转换为C#并在.NET中使用它3.5遇到麻烦,不行。另外,我想使用ConfigurationManager.GetSection的较新的构造。任何人都可以建议如何最好地阅读 system.web / compilation / debug = true | false value?



赞赏!

解决方案

使用:

  HttpContext.Current.IsDebuggingEnabled 

此属性实际上查看了web.config配置设置。如果您使用Reflector查看它,您将发现它使用一些内部类获取实际的ConfigurationSection对象。


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()

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?

Much appreciated!

解决方案

Use:

HttpContext.Current.IsDebuggingEnabled

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中检查Debug是否启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆