How to determine if compilation debug="true" in web.config
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
.
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> elementbool isDebugEnabled = compilationSection.Debug ;
Easy!
<my:control runat="server" id="myid" Visible="<%= HttpContext.Current.IsDebuggingEnabled %>" />
See http://msdn.microsoft.com/en-us/library/system.web.httpcontext.isdebuggingenabled%28v=vs.90%29.aspx
orhttp://www.west-wind.com/weblog/posts/2007/Jan/19/Detecting-ASPNET-Debug-mode with a fruitful feedback below.