Export (0) Print
Expand All

Debug Mode in ASP.NET Applications

To set debug mode for an ASP.NET application, you must edit the application's Web.config configuration file. Usually, the Web.config for your ASP.NET application is located at the same URL location as your application. If your ASP.NET application is at www.microsoft.com/aaa/bbb, the Web.config for the application would normally be www.microsoft.com/aaa/bbb/Web.config.

The Web.config is an XML format file. You can edit the file using any standard text editor or XML parser. You cannot access the file remotely using a Web browser, though. For security reasons, ASP.NET configures Microsoft IIS to prevent direct browser access to Web.config files. If you attempt to access a configuration file using a browser, you will get HTTP access error 403 (forbidden).

The Web.config file contains nested sections marked by tags. The following example shows a typical Web.config file. Look for the <compilation> tag. This marks the beginning of the <compilation> section. In this section, you can specify the debug attribute. In the example shown below, the debug is the second attribute specified in the <compilation> section, but the order does not matter. Attributes are case sensitive, so be sure to specify "debug", not "Debug" or "DEBUG". Set debug to "true", as shown here:

<configuration>
   <system.web>
      <compilation defaultLanguage="VB"
         debug="true"
         numRecompilesBeforeAppRestart="15">
         <compilers>
            <compiler language="VB;VBScript"
               extension=".cls"
               type="Microsoft.VisualBasic.VBCodeProvider,system, Version=1.0.5000.0,  Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            < compiler language="C#;Csharp"
               extension=".cs" 
               type="Microsoft.CSharp.CSharpCodeProvider,system, Version=1.0.5000.0,  Culture=neutral, PublicKeyToken=b77a5c561934e089" />
         </compilers>

         <assemblies>
""            <add assembly="ADODB" />
            <add assembly="*" />
         </assemblies>

         <namespaces>
            <add namespace="System.Web" />
            <add namespace="System.Web.UI" />
            <add namespace="System.Web.UI.WebControls" />
            <add namespace="System.Web.UI.HtmlControls" />
         </namespaces>

      </compilation>
   </system.web>
</configuration>

ASP.NET automatically detects any changes to Web.config files and applies the new configuration settings. You do not have to reboot or restart the server for changes to take effect.

ASP.NET applications inherit settings from Web.config files at higher levels in the URL path. So, if your ASP.NET application is at www.microsoft.com/aaa/bbb, you could specify debug="true" in www.microsoft.com/aaa/Web.config rather than www.microsoft.com/aaa/bbb/Web.config. If you specify debug="true" in www.microsoft.com/aaa/Web.config, the setting will affect all ASP.NET applications lower down (in www.microsoft.com/aaa/bbb, www.microsoft.com/aaa/ccc, www.microsoft.com/aaa/ddd...) unless the setting is overridden in a lower Web.config file. Hierarchical configuration files allow you to change settings for several ASP.NET applications simultaneously.

Enabling debug mode will greatly affect the performance of your ASP.NET application. Remember to disable debug mode before you deploy a release application or conduct performance measurements.

See Also

Debugging an ASP.NET Web Application

Show:
© 2014 Microsoft