Chapter 4
How to test and debug
an ASP.NET application
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 1
Objectives
Applied
Test a file-system web site with the ASP.NET development
server or IIS.
Create and test a local IIS web site.
Test a web site using more than one browser.
Use the debugging techniques presented in this chapter to
determine the cause of runtime or logical errors in any of the
applications you develop.
Knowledge
Explain how a file-system web site can be run under IIS.
Describe how you can test your applications for concurrency
errors.
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 2
Objectives (continued)
Describe the conditions under which an Exception Assistant
dialog box is displayed.
Distinguish between break points and trace points.
Describe the differences between the three Step commands that
you can use to control the execution of an application: Step Into,
Step Over, and Step Out.
Describe the primary use of the Autos, Locals, and Watch
windows.
Describe the use of the Trace feature of ASP.NET.
Describe the use of messages that are written directly to the HTTP
output stream.
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 3
The Order page displayed in the default browser
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 4
Three ways to run an application with debugging
Click the Start Debugging button in the Standard toolbar
Press F5
Choose the DebugStart Debugging command
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 5
Three ways to run an application
without debugging
Press Ctrl+F5
Choose DebugStart Without Debugging
Right-click a page in the Solution Explorer and choose View in
Browser.
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 6
Three ways to stop an application
that’s run with debugging
Press Shift+F5
Click the Stop Debugging button in the Debug toolbar
Choose DebugStop Debugging
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 7
The Browse With dialog box
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 8
An Exception Assistant dialog box
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 9
The dialog box for selecting a local IIS web site
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 10
The dialog box for creating a virtual directory
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 11
The dialog box for specifying a web server
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 12
Limitations of the ASP.NET Development Server
Can serve pages only to the local computer.
Runs in current user’s security context, so it doesn’t accurately
test security issues.
Can’t be configured as an SMTP server, so it can’t be used to
test email applications.
Uses a randomly chosen port rather than the standard HTTP port
80.
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 13
Mozilla Firefox browser outside of Visual Studio
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 14
The Order page with a breakpoint
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 15
The Order page with a tracepoint
and the dialog box used to set it
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 16
Tracepoint output in the Output window
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 17
The Shopping Cart application in break mode
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 18
Commands in the Debug menu and toolbar
Command
Start/Continue
Break All
Stop Debugging
Restart
Show Next Statement
Step Into
Step Over
Step Out
Murach’s ASP.NET 4/C#, C4
Toolbar
Keyboard
F5
Ctrl+Alt+Break
Shift+F5
Ctrl+Shift+F5
F11
F10
Shift+F11
© 2011, Mike Murach & Associates, Inc.
Slide 19
The Code Editor window’s shortcut menu
Run to Cursor
Set Next Statement
Show Next Statement
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 20
The Autos window
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 21
The Locals window
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 22
A Watch window
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 23
The Immediate window
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 24
Beginning of the trace output for the Cart page
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 25
Session and cookies information for the Cart page
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 26
A Page directive that enables tracing
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Cart.aspx.cs"
Inherits="Cart" Trace="true" %>
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 27
Common members of the TraceContext class
Property
IsEnabled
Method
Write(message)
Write(category, message)
Warn(message)
Warn(category, message)
Murach’s ASP.NET 4/C#, C4
Description
True if tracing is enabled for the
page.
Description
Writes a message to the trace
output.
Writes a message to the trace
output with the specified
category.
Writes a message in red type to
the trace output.
Writes a message in red type to
the trace output with the
specified category.
© 2011, Mike Murach & Associates, Inc.
Slide 28
Code that writes a custom trace message
if (Trace.IsEnabled)
{
Trace.Write("Page_Load",
"Binding products drop-down list.");
}
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 29
Trace output that includes a custom message
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 30
The Cart page with output from Response.Write
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 31
Code that writes to the HTTP output stream
protected void Page_Load(object sender, EventArgs e)
{
this.GetCart();
if (!IsPostBack)
{
this.DisplayCart();
Response.Write("Items in cart =
" + cart.Count + "<br />");
}
}
Code that writes HTML output from another class
HttpContext.Current.Response.Write(
"Now updating file.<br />");
Murach’s ASP.NET 4/C#, C4
© 2011, Mike Murach & Associates, Inc.
Slide 32
© Copyright 2026 Paperzz