The point about your question is the difference between compiling in Visual Studio's Debug/Release modes and the Web.config's debug flag.
I'll try to explain you both.
First of all, you must get to know how an ASP.NET application is compiled, otherwise you won't understand the difference between the two compilations.
An ASP.NET application is made by markup (ie. .aspx pages, .ascx controls, .ashx .asmx marker files) and code-behind. Code-behind, from your IDE's point of view (no matter Visual Studio, MonoDevelop, etc.) is a .NET Class Library, ie. a set of classes that don't do anything alone. These can be compiled into Debug or Release mode indifferently by IDE setting. If you compile into Release mode, then calls to Debug
class will be ignored.
What about markup? When you start the web application, the markup files get compiled by the application server to get the final assemblies. For example, a Default.aspx
page with a code-behind file is compiled into a final class that inherits the code-behind class and writes to HTTP output all of its static parts, plus all the controls instantiated in the base class in the positions that have been chosen during design. Inline code (ie. <script runat=server>
tags) gets compiled too. In order to choose the compilation mode, the debug flag in Web.config is used, because you can't determine for sure if an assembly has been compiled in debug or release mode by simply reflecting on it (though there could be some empyrical criteria).
In a few words
- When you call
Debug
class from code-behind, make sure that your IDE compiles the website into Debug mode
- When you call
Debug
class from inline code in markup, make sure you have Web.config's debug flag set
- If you deploy your application as source code (it doesn't work for me in Mono, I must first
xbuild
it), I'm unsure but I believe the debug flag will be used for first compilation stage too
I hope I have been of help!