Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if Debug is enabled in web.config

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!

like image 964
Dscoduc Avatar asked Feb 12 '09 19:02

Dscoduc


People also ask

How do I enable debugging in web config?

In the Web. config file, locate the compilation element. Debugging is enabled when the debug attribute in the compilation element is set to true. Change the debug attribute to false to disable debugging for that application.

How do I disable debugging?

Go to Settings and scroll to the System section (on Android 8 and above, go to Settings > System) Tap Developer Options. Tap the button to toggle developer options Off. USB Debugging is included in the Developer Options.


2 Answers

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.

like image 172
driis Avatar answered Sep 28 '22 08:09

driis


the following should work

var cfg=(System.Web.Configuration.CompilationSection) ConfigurationManager.GetSection("system.web/compilation"); if (cfg.Debug) { ... } 
like image 20
JoshBerke Avatar answered Sep 28 '22 10:09

JoshBerke