How to: Enable Debugging for ASP.NET Applications

This topic applies to:

Edition

Visual Basic

C#

C++

Web Developer

Express

Topic does not apply Topic does not apply Topic does not apply Topic does not apply

Standard

Topic applies Topic applies Topic does not apply Topic applies

Pro and Team

Topic applies Topic applies Topic does not apply Topic applies

Table legend:

Topic applies

Applies

Topic does not apply

Does not apply

Topic applies but command hidden by default

Command or commands hidden by default.

To enable debugging, you must enable it in both the Project Properties page and in the application's web.config file.

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To enable ASP.NET debugging in the project properties (Visual Basic/C#)

  1. In Solution Explorer, right-click the name of a Web project and select Property Pages.

    The <Project> Property Pages appears.

  2. Click the Web tab.

  3. Under Debuggers, select the ASP.NET check box.

To enable debugging in the web.config file

  1. Open the web.config file by using any standard text editor or XML parser.

    1. You cannot access the file remotely by using a Web browser, however. For security reasons, ASP.NET configures Microsoft IIS to help prevent direct browser access to Web.config files. If you try to access a configuration file by using a browser, you will get HTTP access error 403 (forbidden).
  2. Web.config is an XML file, and so contains nested sections marked by tags. The following example shows a typical Web.config file. Modify the file by following these steps:

    1. Locate the <compilation> tag. This marks the beginning of the <compilation> section.

    2. Inside the <compilation> tag, you will create the debug attribute. In the following example , debug is the second attribute that is specified in the <compilation> tag, but the order is not important.

    3. Attributes are case-sensitive, therefore make sure that you specify "debug", not "Debug" or "DEBUG."

    4. Set debug to true, as shown in the following code example.

  3. If you do not set the debug attribute to true and try to launch a debugging session, a dialog box will appear, offering to create a web.config file with the attribute set. Accept, and continue to debug.

Example

<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>

Robust Programming

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

A Web site can contain multiple virtual directories and subdirectories, and Web.config files may exist in each one. ASP.NET applications inherit settings from Web.config files at higher levels in the URL path. Hierarchical configuration files allow you to change settings for several ASP.NET applications at the same time, such as for all applications below it in the hierarchy. However, if debug is set in a file lower in the hierarchy, it will override the higher value.

For example, you could specify debug="true" in www.microsoft.com/aaa/Web.config, and any application in the aaa folder or in any subfolder of aaa will inherit that setting. So if your ASP.NET application is at www.microsoft.com/aaa/bbb, it will inherit that setting, as will any ASP.NET applications in www.microsoft.com/aaa/ccc, www.microsoft.com/aaa/ddd, and so on. The only exception is if one of those applications overrides the setting by means of its own lower Web.config file.

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

Other Resources

Debugging ASP.NET and AJAX Applications