ASP.NET
  Home arrow ASP.NET arrow Page 4 - Advanced Testing and Debugging of an ASP.N...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Advanced Testing and Debugging of an ASP.NET 2.0 Application
By: Murach Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2006-05-25

    Table of Contents:
  • Advanced Testing and Debugging of an ASP.NET 2.0 Application
  • How to use the Trace feature
  • How to create custom trace messages
  • How to write information directly to the HTTP output stream

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Advanced Testing and Debugging of an ASP.NET 2.0 Application - How to write information directly to the HTTP output stream


    (Page 4 of 4 )


     
    Another way to display information as a program executes is to write it directly to the HTTP output stream. To do that, you use the Write method of the HTTP Response object as shown in figure 4-17. When you use this technique, you’ll want to be sure to remove any statements you’ve added when you finish testing your application.

    At the top of this figure, you can see a Cart page that includes output that indicates the number of items that are currently in the shopping cart. To generate this output, I added a Response.Write method to the Page_Load event handler of the page. As you can see, this event handler uses the Count property of the Cart object to determine the number of items that are in the cart.

    Notice that the text you include on the Write method can include HTML tags. For example, the Write method shown here includes a <br /> tag so that the item count is followed by a blank line. Also note that the output you write to the output stream is always added to the beginning of the stream. Because of that, it always appears at the top of the browser window.

    The Cart page with output generated by Response.Write


    Figure 4-17.  How to write information directly to the HTTP output stream 

    A Page_Load event handler 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 />");

    Description

    1. The Write method of the HttpResponse object provides a convenient way to write data directly to the HTTP output stream. The output can include any valid HTML.
    2. To access the HttpResponse object from the code-behind file for a web page, you use the Response property of the page. To access this object from a class that doesn’t inherit the Page class, you use the Response property of the HttpContext object for the current request. To access this object, you use the Current property of the HttpContext class.
    3. The HTML output you add to the HTTP output stream using the Write method of the HttpResponse object appears at the beginning of the output stream. As a result, the output from the Write method always appears at the top of the page in the browser window.

    Perspective
     
    As you can now appreciate, Visual Studio provides a powerful set of tools for debugging ASP.NET applications. For simple applications, you can usually get the debugging done just by using breakpoints, data tips, and the Autos window. You may also need to step through critical portions of code from time to time. For complex applications, though, you may discover the need for some of the other features that are presented in this chapter. With tools like these, a difficult debugging job becomes manageable.

    Terms
     
    virtual directory
    virtual root
    active mode
    passive mode
    Remote Debug Monitor
    browse location
    concurrency
    concurrency error
    break mode
    Exception Assistant
    stack trace
    debugger
    breakpoint
    Breakpoints window
    tracepoint
    Output window
    data tip
    Immediate window
    Autos window
    Locals window
    Watch window
    watch expression
    Trace feature


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "Murach's ASP.NET 2.0 Web Programming with...
     

    Buy this book now. This article is excerpted from chapter four of the book Murach's ASP.NET 2.0 Web Programming with VB 2005, written by Joel Murach and Anne Boehm (Murach, 2006; ISBN: 1-890774-32-4). Check it out today at your favorite bookstore. Buy this book now.

    ASP.NET ARTICLES

    - Developing a Mini ASP.NET AJAX Server Centri...
    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT