Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if compilation debug="true" in web.config

I am drawing a blank here for something that should be simple...

I am trying to do something like:

    <my:control runat="server" id="myid" Visible="<%= (is compilation debug mode?) %>" /> 
like image 583
Outside the Box Developer Avatar asked May 31 '11 20:05

Outside the Box Developer


People also ask

Is compilation debug true?

config file, locate the compilation element. Debugging is enabled when the debug attribute in the compilation element is set to true. If the debug attribute is true, change the debug attribute to false.

What is the default value for compilation debug?

The default value is false, but beware of ASP.NET Configuration File Hierarchy and Inheritance. If you use the the IIS configuration editor, you can see the actual values. A drop down list allows you to inspect the values set at a higher level. You can see that the value of debug=true.

What is debug true?

debug=true is for debugging during development. It creates debugging symbols used to provide metadata about the current executing code. debug=false is is for deployment to a production server.

What is Web debug config?

This is the transform that is applied when you publish your application to the development staging environment. This would make changes to the web. config which are required for the target environment.


2 Answers

The HttpContext.IsDebuggingEnabled property:

using System.Web;  if (HttpContext.Current.IsDebuggingEnabled) { /* ... */ } 

From the documentation:

Gets a value indicating whether the current HTTP request is in debug mode[…] true if the request is in debug mode; otherwise, false.

like image 198
Adrian Salazar Avatar answered Sep 30 '22 07:09

Adrian Salazar


This should get you the <compilation> element in the <system.web> section group:

using System.Web.Configuration ;  . . .  CompilationSection compilationSection = (CompilationSection)System.Configuration.ConfigurationManager.GetSection(@"system.web/compilation") ;  . . .  // check the DEBUG attribute on the <compilation> element bool isDebugEnabled = compilationSection.Debug ; 

Easy!

like image 24
Nicholas Carey Avatar answered Sep 30 '22 08:09

Nicholas Carey