Exforsys

VB.NET 2005

  1. VB.NET 2005 Free Training
  2. The .NET Framework Architecture Part 1
  3. The .NET Framework Architecture Part 2
  4. Application Class and Message Class
  5. Implementing Class Library Object
  6. Visual Studio.NET Namespaces
  7. .NET Assemblies
  8. Differences between VB.NET 1.0 and VB.NET 2.0
  9. Introducing VB.NET Windows Forms
  10. Visual Studio Windows Forms Designer
  11. Exploring the Forms Designer generated code
  12. Setting and Adding Properties to Windows Form
  13. Implementing Inheritance
  14. Event Handling In Visual Basic .NET
  15. Building Graphical Interface elements
  16. .NET Common Windows Forms Controls Part 1
  17. .NET Common Windows Forms Controls Part 2
  18. Common Controls and Handling Control Events
  19. DomainUpDown and NumericUpDown Controls
  20. Dialog Boxes in Visual Basic .NET
  21. Visual Studio Adding Controls to Windows Form
  22. VB.NET Validation Controls
  23. Working with Menu Controls
  24. VB.NET MDI Applications
  25. .NET Exceptions
  26. VB.NET Creating and Managing Components Part 1
  27. VB.NET Creating and Managing Components Part 2
  28. Simple Data Binding
  29. .NET Complex Data Binding
  30. .NET Data Form Wizard
  31. Data Manipulation with ADO.NET
  32. SQL Server Stored Procedures
  33. SQL Server Ad Hoc Queries
  34. Finding and Sorting Data in DataSets
  35. ADO.NET Object Model
  36. Working with DataSets
  37. Using XML Data
  38. Working with File System in .NET
  39. Creating Web Service
  40. Instantiating - Invoking Web Services, Creating Proxy Classes with WSDL
  41. Web Reference and Web Services
  42. Web Services - SOAP, WSDL, Disco and UDDI
  43. Web Application Testing in VB.NET 2005
  44. Web Application Tracing and Debugging
  45. Working with Legacy Code and COM Components
  46. ActiveX Controls and Legacy Code
  47. Windows Application Testing
  48. VB.NET Windows Application Testing
  49. Tracing VB.NET Windows Application
  50. Debugging Windows Applications In Visual Studio.NET 2005
  51. Deploying Windows Applications In Visual Studio.NET 2005
  52. Customizing Setup Project in Visual Studio.NET 2005
  53. Shared Assembly
  54. Microsoft .NET Creating Installation Components
  55. The Registry Editor in Visual Studio.NET 2005
  56. The File Types Editor

Ads


Home arrow Technical Training arrow VB.NET 2005

Web Application Tracing and Debugging

Page 1 of 3
Author : Exforsys Inc.     Published on: 30th Jul 2005    |   Last Updated on: 24th Dec 2007

Tracing and Debugging a Web Application

In this tutorial you will learn how to trace and debug a web application.
  • Tracing - Using the TraceContext class, Using Trace and Debug, Trace listeners, Trace Switches and Conditional Compilation.
  • Debugging - you will learn setting breakpoints and conditional breakpoints, how to debug a running process and also about debugging a remote process.

Ads

Tracing

This class is used to append messages to specific trace categories. For example, if the developer is creating an instance of the System.Web.UI.WebControls.Calendar class for the application, he might include the trace message "Starting To Render" in a rendering procedure, and "Firing OnChange Event" in an event handler procedure. The System.Web.TraceContext class is used to obtain a set of trace records at the end of request execution for custom processing. To enable tracing, set the Trace attribute in the [] directive or the System.Web.TraceContext.IsEnabled property to true. When tracing is enabled, in addition to showing user-provided trace content, the System.Web.UI.Page class automatically includes performance data, control-tree structure information, and state management content for every request.

Using the TraceContext class

The TraceContext Class captures and presents execution details about a web request. This class cannot be inherited. It is available in the System.Web namespace. This object can be declared and instantiated in the following manner.

Dim ctxt As HttpContext
Dim txtxt As New TraceContext(ctxt)

This class can be used to append messages to specific trace categories. If an instance of a calender class is being created for the application, a trace message may be included such as-- “Starting to render” in the rendering procedure, and “Firing OnChange Event” in an event handler procedure. In this case the TraceContext class can be used to obtain a set of trace records at the end of request execution for custom processing.

Using Trace and Debug

It is not always possible to use the debugger. In such circumstances tracing becomes a useful alternate. If the pages are hosted on a remote server the debugger may not be available. Tracing also makes it easy for the user see information, such as the HTTP header, that is not explicitly available in the debugger.

The website used for consuming web services may be used again to study the impact of tracing. To the solution add a new item by right-clicking on the project in the solution explorer. In the templates dialog box choose Web Form. In the name box type TraceTestPage.aspx. Now proceed to add one TextBox, one Button and a label.

Now add code to the page. When the page is running without any problem, the user can enter a name and click the button, which displays the name in the label control. If the user closes the browser and then comes back to this page, the page will already have the user’s name, because it is stored in a cookie.

To add code right-click on the name of the page in the solution explorer and click view code. Inside the class definition, you can enter the following code:

Partial Class TraceTestForm_aspx
Inherits System.Web.UI.Page
Sub buttonDisplayName_Click(ByVal sender As Object, _
ByVal e As EventArgs)
Label1.Text = Server.HtmlEncode(TextBox1.Text)
Response.Cookies("username").Value = Label1.Text
End Sub
End Class

The code performs the following tasks:

It reads the value of the TextBox control and displays the name in the Label control. As part of this logic, the code calls the System.Web.HttpServerUtility.HtmlEncode method, which turns potentially executable HTML characters such as < into their display equivalents. This is a security measure to prevent scripting exploits. The code creates a cookie named username that stores the value that the user has entered.

When the application is built and executed, the web page appears. Type a name in the browser and click the submit button. When the post back of the page takes place, the posting takes place. The name is not displayed in the label1.

To enable tracing to be true, do the following:

1. Switch to Default.aspx and switch to Design view.
2. In the drop-down list at the top of the Properties window, select DOCUMENT.
3. This displays properties for the page.
4. Set Trace to true.

The trace setting is actually made as part of the @ Page directive. This can be seen by switching to Source view and looking at the first line in the page. The @ Page will look like this:

Sub buttonDisplayName_Click(ByVal sender As Object, _
ByVal e As EventArgs)
Trace.Warn("debugging", "Start buttonDisplayName Click handler")
Label1.Text = Server.HtmlEncode(TextBox1.Text)
Response.Cookies("username").Value = Label1.Text
Trace.Warn("debugging", "End buttonDisplayName Click handler")
End Sub

The page when executed does not produce the desirable out put. The out put that appears is displayed below with the trace information:

When the trace output is examined, it is clear that the output contains no red text. You can conclude from this that the button's Click handler is not being called. Now add the following code to the program instead of the code available for the button. The code will look like the following listing:

Click here to view sample code

The output generated looks like the graphic shown below:

The desired result is achieved. The most common reason that a handler is not called is that the control has not been properly bound to the event handler. That is true in this case — although the event-handling code has been added, the button's Click event was not bound to the handler. (Normally, Visual Web Developer binds the event to the control when the control is double-clicked in Design view.). Now the corrected the code creates the desired result. The red colored text indicates that that the button’s click handler is called.



 
This tutorial is part of a VB.NET 2005 tutorial series. Read it from the beginning and learn yourself.

VB.NET 2005

  1. VB.NET 2005 Free Training
  2. The .NET Framework Architecture Part 1
  3. The .NET Framework Architecture Part 2
  4. Application Class and Message Class
  5. Implementing Class Library Object
  6. Visual Studio.NET Namespaces
  7. .NET Assemblies
  8. Differences between VB.NET 1.0 and VB.NET 2.0
  9. Introducing VB.NET Windows Forms
  10. Visual Studio Windows Forms Designer
  11. Exploring the Forms Designer generated code
  12. Setting and Adding Properties to Windows Form
  13. Implementing Inheritance
  14. Event Handling In Visual Basic .NET
  15. Building Graphical Interface elements
  16. .NET Common Windows Forms Controls Part 1
  17. .NET Common Windows Forms Controls Part 2
  18. Common Controls and Handling Control Events
  19. DomainUpDown and NumericUpDown Controls
  20. Dialog Boxes in Visual Basic .NET
  21. Visual Studio Adding Controls to Windows Form
  22. VB.NET Validation Controls
  23. Working with Menu Controls
  24. VB.NET MDI Applications
  25. .NET Exceptions
  26. VB.NET Creating and Managing Components Part 1
  27. VB.NET Creating and Managing Components Part 2
  28. Simple Data Binding
  29. .NET Complex Data Binding
  30. .NET Data Form Wizard
  31. Data Manipulation with ADO.NET
  32. SQL Server Stored Procedures
  33. SQL Server Ad Hoc Queries
  34. Finding and Sorting Data in DataSets
  35. ADO.NET Object Model
  36. Working with DataSets
  37. Using XML Data
  38. Working with File System in .NET
  39. Creating Web Service
  40. Instantiating - Invoking Web Services, Creating Proxy Classes with WSDL
  41. Web Reference and Web Services
  42. Web Services - SOAP, WSDL, Disco and UDDI
  43. Web Application Testing in VB.NET 2005
  44. Web Application Tracing and Debugging
  45. Working with Legacy Code and COM Components
  46. ActiveX Controls and Legacy Code
  47. Windows Application Testing
  48. VB.NET Windows Application Testing
  49. Tracing VB.NET Windows Application
  50. Debugging Windows Applications In Visual Studio.NET 2005
  51. Deploying Windows Applications In Visual Studio.NET 2005
  52. Customizing Setup Project in Visual Studio.NET 2005
  53. Shared Assembly
  54. Microsoft .NET Creating Installation Components
  55. The Registry Editor in Visual Studio.NET 2005
  56. The File Types Editor
 

Comments