Use tracing to learn how your application is running.
Debug ASP.NET applications.
Use the Visual Studio .NET debugger.
This book has covered a wide variety of topics related to ASP.NET development. I hope you’ll be able to avoid most problems while developing your ASP.NET Web applications. Inevitably, however, there will be times when your code doesn’t do what you expect it to, or you’ll run into errors or problems that prevent your application from working. This final chapter will look at what to do when that happens. It’s not intended to make you an expert debugger, but rather to give you an overview of the tools available for debugging in ASP.NET.
To say that classic ASP did not offer developers much support for debugging their applications would be a colossal understatement. Despite being a very simple and productive development environment, classic ASP left a lot to be desired in terms of debugging and error messages.
For example, in classic ASP you had no convenient way to access the state of the current HTTP request or of the other collections, such as the QueryString or Forms collections. ASP.NET addresses this issue through a new feature called tracing, which I’ll discuss in the first part of this chapter.
Additionally, classic ASP error messages were often cryptic at best. If you were lucky, they told you the line of the ASP page on which the error occurred. Unfortunately, this information could be misleading. The error might have occurred in a function called by that page, but you wouldn’t know that from the error message. ASP.NET provides much richer error reporting, including a stack trace of the functions that led up to an error condition, making it much easier to locate the root cause of the error.
The Microsoft .NET Framework SDK ships with its own debugger, so developers who are not using Microsoft Visual Studio .NET can attach it to the process of their ASP.NET application and step through their code to find and fix problems. Most often, however, using the debugger in Visual Studio .NET can be the most efficient way to debug your application. I’ll discuss the improved error reporting and the SDK debugger in the second half of this chapter.