Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 17

Developing Web

Applications Using
Microsoft® Visual
Studio® 2008
Module 5: Tracing in Microsoft ASP.NET
Web Applications
• Tracing and the Trace Object

• Remote Debugging
Lesson: Tracing and the Trace Object
• Run Time Information

• Enabling Tracing

• The Trace Object

• Viewing Trace Results

• Application-Level Trace

• Demonstration: Tracing Through a Web Application

• Tracing into a Component


Run Time Information
• During run time, you can:
 Output values of variables
 Assert whether a condition is met
 Trace through the execution path of the application

• You can collect run time information by using:


 The Trace object
 The Debug object
Enabling Tracing
• Page-level tracing displays trace statements only on
the configured page
• Trace attribute

<%@ Page Trace="true" %>

• Application-level tracing displays trace information for


all pages in a Web application
• Trace element in the Web.config file

<trace enabled="true" pageOutput="true"


localOnly="true"/>
The Trace Object
• Inserting trace messages

Trace.Write ("category", "message")

• Conditional execution with Trace.IsEnabled

If Trace.IsEnabled Then
message = "Tracing is enabled!"
Trace.Write("myTrace", message)
End If

if (Trace.IsEnabled)
{
message = "Tracing is enabled!";
Trace.Write("myTrace", message);
}
• Changing state of trace dynamically

Trace.IsEnabled = False
Viewing Trace Results
Application-Level Trace

Page Application Result


Trace=True or Trace results are
Trace=True
Trace=False displayed on page
Trace=True or Trace results are
Trace=False
Trace=False not displayed
Trace results are
Trace not set Trace=True
displayed on page

• Application-level trace • Trace results are also


statements are displayed viewable by using the
on individual pages trace viewer
http://server/project/trace.axd
Demonstration: Tracing Through a Web Application
• Page-level tracing

• Application-level tracing
Tracing into a Component
• Import the System.Web library

• Enable tracing

HttpContext.Current.Trace.IsEnabled = True

HttpContext.Current.Trace.IsEnabled = true;

• Call Trace methods

HttpContext.Current.Trace.Write _
("component", "this is my trace statement")

HttpContext.Current.Trace.Write
("component", "this is my trace statement");
Lesson: Remote Debugging
• Remote Debugging Overview

• Performing Remote Debugging


Remote Debugging Overview
• Remote debugging:
 Enables you to debug Web applications remotely
 Simplifies team development
 Simplifies Web site management

• Options for remote debugging:


 Install the Remote Debugging Monitor (msvsmon.exe) on the
remote computer
 Run the Remote Debugging Monitor remotely from a share
Performing Remote Debugging

11 Start msvsmon.exe on the remote computer

22 On the local computer, start Visual Studio 2008

In Visual Studio 2008, open the Attach to Process


33 dialog box

44 Connect to the remote computer

55 Attach to the worker process of the remote application

Open a browser and enter the URL to the


66 remote application
Lab: Tracing in Microsoft ASP.NET Web Applications
• Exercise 1: Implementing Trace Statements

• Exercise 2: Tracing into a Component

Logon information

Virtual machine 2310C-LON-DEV-05


User name Student
Password Pa$$w0rd

Estimated time: 30 minutes


Lab Scenario

Master Page
Logon Page benefitsMaster.master
login.aspx
Benefits Lab Web
Home Page Application
ASPState
Default.aspx Page Header
header.ascx
Menu Component
Registration Benefits.cs or Benefits.vb
register.aspx TempDB
Web.
config

Life Insurance Retirement Medical Dentists


life.aspx retirement.aspx medical.aspx dental.aspx

Prospectus
prospectus.aspx Doctors User Control XML Web
LINQ to SQL doctors.aspx nameDate.ascx Service
Classes DentalService1.asmx
Doctors.dbml

Doctors Dentists
XML Files
Lab Review
Review Questions
• What steps are required to view tracing output on a
specific page?
• What steps are required to enable application-level
tracing?
• What code is required to explicitly turn on tracing in a
component?
Module Review and Takeaways
• Review Questions

• Best Practices

• Tools

You might also like