TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

ASP.NET IsDebuggingEnabled

This C# example uses the IsDebuggingEnabled property in ASP.NET.

IsDebuggingEnabled detects Debug mode on a website.

Debug mode has severe performance negatives during runtime. We see an example of using the IsDebuggingEnabled property on HttpContext. We also look at the default setting in ASP.NET.

Example. First, we see how the IsDebuggingEnabled property is used in ASP.NET, in a simple Web Forms page. You can access the HttpContext anywhere with HttpContext.Current, not just in a Page.

Note: Here we have a Page code-behind file. The Response and Context objects are called intrinsic objects and are available in the Page.

Also: You can access these intrinsic objects by calling base.Response, for example.

Example that demonstrates IsDebuggingEnabled: C#

using System;
using System.Web.UI;

public partial class _Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
	Response.Write(Context.IsDebuggingEnabled);
	// also: // HttpContext.Current.IsDebuggingEnabled
    }
}

Default? Debug mode is not the default. I determined this is by creating a new web site project in Visual Studio, and then running the above page, Default.aspx. When you do not set debug="true" in Web.config, the site is compiled in Release mode.

Comment from Web.config

<!--
    Set compilation debug="true" to insert debugging
    symbols into the compiled page. Because this
    affects performance, set this value to true only
    during development.
-->

This comment hints that debug mode is only enabled when 'true' is set. However, it doesn't clearly say that unless true is set, the value is false. This article shows that false is the default and is used when the attribute is missing.

Summary. We saw the IsDebuggingMode property on HttpContext, which can be used when you are unsure if debugging is enabled. We also saw that you only need to worry about debugging mode at all if the attribute is present in Web.config.

Ideally: Your web application will have no behavioral difference in Debug mode. This would make it much easier to diagnose problems.


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf