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

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!