Export (0) Print
Expand All

How to: Enable Debugging for ASP.NET Applications

This topic applies to:

Visual Studio

Visual Basic

C#

C++

J#

Visual Web Developer

Express

No

No

No

No

No

Standard

Yes

Yes

Yes

Yes

Yes

Pro/Team

Yes

Yes

Yes

Yes

Yes

To enable debugging, you must enable it in the project properties, and in the application's web.config file.

NoteNote

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 debugging in the project properties

  • In Visual Studio 2005, use the <Project> Property Pages to set project properties for Web application debugging by doing the following:

    1. Open the Property Pages by right-clicking the project name in Solution Explorer, and selecting Property Pages.

    2. Click the Start Options tab.

    3. Under Debuggers, make sure the ASP.NET box is selected.

To enable debugging in the web.config file

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

    1. You cannot access the file remotely using a Web browser, though. For security reasons, ASP.NET configures Microsoft IIS to help 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).

  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 doing the following:

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

    2. Inside the <compilation> tag, you will create the debug attribute. In the example shown below, debug is the second attribute specified in the <compilation> tag, but the order does not matter.

    3. Attributes are case sensitive, so be sure to 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 attempt to debug, a dialog box will appear offering to create a web.config file with the attribute set. Accept, and continue debugging.

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 reboot 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 simultaneously, 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

Community Additions

ADD
Show:
© 2014 Microsoft