Connect Tech Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Sunday, 3 June 2012

How to Capture ASP.NET Page Trace Events in IIS 7.0 Tracing

Posted on 00:02 by Unknown

Introduction

In ASP.Net today, developers can add trace events to ASPX pages using Trace.Write() & Trace.Warn() calls in the script sections of their page.  Typically, you use these traces to debug an application that does not work as expected. 
These events appear when you enable tracing for the page (set <%@ Page Trace="True"  %>).  You can only view these events by default when browsing the application from the server (i.e. Localhost), or when you enable Application Tracing to keep the last given number of sessions. 
However, the problems with this process are:
  • These traces are not persisted, so if the process goes away, so do your traces
  • These traces are collected regardless of the status code for the request – i.e. if it succeeds or fails, you get traces
  • These traces are viewed completely separately from any other infrastructure traces provided by IIS 7.0 or ASP.net
In IIS 7.0, you can now collect these traces in Failed Request Tracing or ETW tracing in addition to viewing them normally.  And, you can view these traces in conjunction with IIS and ASP.net infrastructure traces. 
Tasks illustrated in this walkthrough include:
  • Configuring failed-request tracing to capture ASP.net Page Trace.Write and Warn calls 
  • Generating the failure condition and viewing the resulting trace capture, finding the Trace.Write and Trace.Warn calls.

Prerequisites

The following steps include the prerequisites necessary for completing the tasks in this article.

Step 1 : Installing IIS 7.0

IIS 7.0 must first be installed.  To check if IIS 7.0 is installed, browse to http://localhost. If you see the "under construction" page, then IIS 7.0 is installed.  If IIS 7.0 is not installed, refer to the "Installing IIS 7.0" guide for installation instructions. 
Make sure to install the following IIS 7.0 Components:
  • ASP (under World Wide Web Services => Application Development Features => ASP)
  • Tracing (under World Wide Web Services => Health & Diagnostics => Tracing)

Step 2 : Log In as Administrator

Make sure to login to the administrator account or in the Administrators group. 
Note: Being in the Administrators group does not grant you complete administrator privileges by default.  You must run many applications as Administrator. Right-click the application icon and choose "Run as Administrator". 

Step 3 : Make a Backup

You must make a backup of the configuration before executing tasks in this article.  Run the following:
    1. Click the Start button -> All Programs -> Accessories -> (r-click)Command Prompt -> Run as Administrator.

    2. Execute the following command in that command prompt:
%windir%\system32\inetsrv\appcmd add backup

Adding a New Trace.Write() & Trace.Warn() Call to a Sample ASPX Page

In this task, you add Trace.Write() & Warn() calls to a sample aspx page and view the resulting traces in your browser.
  1. Use the Administrator command prompt and navigate to your %systemdrive%\inetpub\wwwroot directory.
  2. Use your editor of choice and create an aspx page called trace.aspx, putting the following code in the page:
<%@ Page language="C#" trace="true" %>

<%
  Trace.Write("Hey, there");
  Trace.Warn("Doh, a warning");

  Response.Write("hello, world");
%>
3. Browse to http://localhost/trace.aspx. You see the following:


Notice the events above: "Hey, there" and "Doh, a warning". 
We have just added a new event to our page.  Now see if we can get Failed Request Tracing to capture it.

Adding a New Trace.Write() & Trace.Warn() call to a Sample ASPX Page

The page is now instrumented with Trace.Write & Trace.Warn calls.  Configure Failed Request Tracing to capture the ASPX page Trace.Write() & Warn() calls. 
For this scenario, we must use the ASP.Net provider's Page area, with Trace.Write calls corresponding to the Verbose verbosity level, and Trace.Warn() calls corresponding to the Warning verbosity level.  Setting the verbosity level to Verbose gets both.

Step 1 : Enabling Failed Request Tracing for Your Site

Failure Request Tracing first must be enabled for the site.  Steps to enable are found in the HOWTO-FailureRequestTracing Walk Through, Task 1. 

Step 2 : Creating a Failed Request Tracing Rule to Capture the Trace.Write() & Warn() Events

    1. From the Administrator command prompt, type start inetmgr. In the Connections panel, expand the machine name, then Sites folder, then click  theDefault Web Site. Under IIS, double-click Failed Request Tracing Rules.

   2. In the Actions pane, click Add…. to launch the Add Failed Request Tracing Rule wizard. On the Specify Content to Trace page, click theASP.NET (*.aspx) option for what to trace and click Next. 


    3. In the Define Trace Conditions screen, check the Status Codes check box and enter "200" as the status code to trace.



  4. Click Next. The Select Trace Providers page appears. Select the ASPNET check box and the Page check box under "Areas" (uncheck all other areas that are checked except Page) Under Verbosity, select Verbose.


 5. Click Finish.  You see the following definition for the Default Web Site:


Step 3 : Test and View

In this step, we generate a request for http://localhost/trace.aspx and then check the Failed Request Tracing log file to see the trace events. 
To verify that it worked:
  1. Open an Administrator-elevated new Internet Explorer window.
  2. Type in the address http://localhost/trace.aspx. 
  3. We generated the traced request, so open an Administrator-elevated Internet Explorer window, enter CTRL-O to open a file, and navigate to inetpub\logs\FailedReqLogFiles\W3SVC1 folder.  In the HTML Files dropdown list, select All Files.
  4. Select the most recent FR######.xml file.  You see the following:



The events display above in the trace log.  Notice that the event "Doh, a warning"'s SubType Name is "AspNetPageTraceWarnEvent" - that is the Trace.Warn() event. 
All Trace.Write() calls are very high verbosity (verbosity = "Verbose");  hence, the reason for the <Level>5</Level>, while all Trace.Warn() calls are logged as Warnings. 
Note: There are many other "AspNetPageTraceWriteEvent" events logged.  This is because all the other entries in the trace table, like Begin PreInit, etc., are all logged through the same infrastructure as well. 

Summary

We finished adding trace messages to the ASPX page. We configured IIS 7.0 to capture those traces, when enabled, in the Failed Request Trace Logfile. Remember that these trace entries are only logged to the trace logs if the page's trace="true" directive is set, and the ASP.NET provider with the "Page" area is defined when tracing (either using ETW or Failed Request Tracing).

Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • How to schedule a PHP script in task scheduler
    Quiet often there is a need to execute/run  php  script on some time interval at server side. And that php scripts should run automatically ...
  • HTTP Error 403.19 – Forbidden The configured user for this application pool does not have sufficient privileges to run CGI applications.
    If you get the error “HTTP Error 403.19 – Forbidden The configured user for this application pool does not have sufficient privileges to...
  • Roles and Features showing an error HRESULT: 0x800F0818 in Server Manager of windows server 2008 R2
    When you open Server Manager both Roles and Features display Error and you are unable to add any role or features. When you select the det...
  • Error - "Failed to retrieve data for this request (Microsoft.SqlServer.Management.sdk.sfc)"
    ErrError    - In Microsoft SQL Management Studio 2008, you receive the following error message when you try to expand the Databases:      ...
  • How to configure IIS 7 to redirect non-www domain to www domain?
    One of few legacy leftovers that was never dropped over the years is the common use of www domain prefix. It is not a problem per se for us...
  • Back up all MS SQL databases at once
    This article will discuss how to backup all MS SQL databases with one script. A separate file will be created for each database. Log into ...
  • The media family on device is incorrectly formed. SQL Server cannot process this media family Error: 3241
    When you try to restore a backup of the database you get the following error: The media family on device ” is incorrectly formed. SQL Server...
  • How to check Malware injection in Code
    To check Malware injection in your script/Code you can use a Web based Google Tool called “Webmasters Tools” You can find it here Google We...
  • An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.
    If you are facing the following error while accessing the website: Error Summary HTTP Error 500.24 - Internal Server Error An ASP.NET settin...
  • Stopping Unneeded Services In Windows Server 2008
    By  default Windows 2008 starts with a number of services that actually do not need to be running. Many of these services can impact perfo...

Categories

  • booting Process
  • linux
  • redhat

Blog Archive

  • ►  2013 (68)
    • ►  July (1)
    • ►  May (2)
    • ►  April (11)
    • ►  March (54)
  • ▼  2012 (44)
    • ►  September (20)
    • ►  August (1)
    • ►  July (4)
    • ▼  June (12)
      • Enable Canonical URL in IIS7 for SEO
      • How to disable web.config Inheritance for Child Ap...
      • New in IIS 7 - App Pool Isolation
      • Application Pool Identities
      • Ensure Security Isolation for Web Sites
      • Getting Started with AppCmd.exe
      • Introduction to ApplicationHost.config
      • How to Capture ASP.NET Page Trace Events in IIS 7....
      • Installing and Configuring Web Deploy
      • Classic ASP parent paths are disabled by default
      • Classic ASP Script Error Messages No Longer Shown ...
      • Classic ASP Not Installed by Default on IIS 7.0 an...
    • ►  May (2)
    • ►  March (4)
    • ►  February (1)
  • ►  2011 (1)
    • ►  February (1)
  • ►  2009 (9)
    • ►  September (3)
    • ►  August (2)
    • ►  June (1)
    • ►  May (2)
    • ►  March (1)
Powered by Blogger.

About Me

Unknown
View my complete profile