How to: Enable Debugging for ASP.NET Applications
This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, use the version selector at the top left. We recommend upgrading to Visual Studio 2019. Download it here
To enable debugging, you must enable it in both the Project Properties page and in the application's web.config file.
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 Customizing Development Settings in Visual Studio.
To enable ASP.NET debugging in the project properties (Visual Basic/C#)
In Solution Explorer, right-click the name of a Web project and select Properties.
In the project properties page click the Web tab.
Under Debuggers, select the ASP.NET check box.
To enable debugging in the web.config file
Open the web.config file by using any standard text editor or XML parser.
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).
Web.config is an XML file, and so contains nested sections marked by tags. Locate the
configuration/system.web/compilationelement. If the compilation element does not exist, create it.
compilationelement does not contain a
debugattribute, add the attribute to the element.
Make sure the
debugattribute value is set to
The web.config file should look like the following example. Note that there can be sections between the configuration and system.web elements
element sections between the configuration and system.web elements
element sections between the system.web and compilation elements
The compilation element can contain other attributes and elements
<configuration> ... <system.web> <compilation debug="true" ... > ... </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 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.