Troubleshooting websites

Implementing Tracing

In ASP.NET trace data logged to file that is accessible via web browser.

Can inject own tracing calls into this log.

Enabled via web.config file or the ASP.NET Web Site Administration Tool (WSAT).

Includes information such as:

Trace SectionDescription
Request DetailsGeneral details on request
Trace InformationPerformance info related to page life-cycle events
Control TreeInfo on each control on page, e.g. size
Session StateDisplays session variables
Application StateDisplays application variables
Request CookiesDisplays request cookies passed to server
Response CookiesDisplays response cookies sent from server
Headers CollectionThe HTTP headers sent to server by client
Form CollectionList of values posted back to server
QueryString Collection  List of values in query string
Server VariablesDisplays server variables

 

Enabling via WSAT

From Visual Studio select Website | ASP.NET Configuration

Click Application tab of WSAT

Click Configure Debugging and Tracing

Tick Capture tracing information

Trace Settings

WSATWEB.CONFIGDescription
Capture Tracing InformationenabledEnables application tracing
Display Tracing Info On Individual Pages  pageOutputWhen true trace infor displayed directly on web page being traced
Display Trace Output ForlocalOnlyWhen set to "Local Requests Only" tracing only takes place for requests from machine on which web server is running. "All Requests" will trace requests from any machine.
Sort OrdertraceModeSort trace output by time or category
Number of trace requests to cacherequestLimitNumber of records to hold in trace log
Select which trace results to cachemostRecentWhen set to "Most Recent" trace cache continues to update, overwriting older entries. When set to "Oldest Trace Results" the cache no longer updates once full.

 

Enabling via web.config

Edit attributes of trace element:

<system.web>
  <trace enabled="true" pageOutput="false" localOnly="false" mostRecent="true" />
</system.web>

Tracing at Page Level

Can enable tracing for specific pages via @ Page directive:

<@ Page trace="true" %&>

View trace data

Can view on each webpage or the entire log at the http://server/application/trace.axd page.

Displaying trace on individual pages can be a security loophole - disable on production environments.

Custom Data

Use Trace class to add own trace messages.

Member of the Page object

Use Write method to add entries to trace log.

Tracing AJAX Applications

No server process on which to rely, instead have to debug code as executes in browser.

Microsoft AJAX libray provides Sys.Debug client-side namespace, includes assert, trace, clearTrace, traceDump and fail methods.

Output goes to Visual Studio output window and in Text Area control on page including your JavaScript - providing the Text Area has an ID of "TraceConsole". If browser has debugging console then output will also appear there.

Monitoring Running Applications

Provides info on overall application health.

Set of classes in System.Web.Management used for health tracking.

Health Monitoring Classes

Work by raising and logging events.

Enable individual events based on what aspects of application are to be monitored.

First step is to determine which events to listen for. Events are defined as classes. The classes based on hierarchy that defines data to be logged.

Can derive your own classes from these to write custom health monitoring.

ClassDescription
WebBaseEventBase class for web events
WebManagementEventWeb events that contain application process information
WebHeartbeatEventPeriodic event raising info about app at set intervals
WebRequestEventContains web request info
WebApplicationLifetimeEventRaised when significant event occurs, e.g. start or shutdown
WebBaseErrorEventError based events
WebErrorEventProvides info on error when occurs
WebRequestErrorEventRequest data for request errors
WebAuditEventCreates audit (Security) events
WebSuccessAuditEventRaised when successful security operation occurs
WebAuthenticationSuccessAuditEvent  Provides info when successful user authentication occurs
WebFailureAuditEventRaised when failed security operation occurs
WebAuthenticationFailureAuditEvent  Raised when failed attempt at user authentication occurs
WebViewStateFailureAuditEventRaised when view state fails to load

 

When no which events to listen for, enable a listener.

ASP.NET provides set of listeners used to collect web event information.

Can write own custom listeners by extending existing WebEventProvider class.

Configuring Health Monitoring

Turn on web events and connect to listeners via web.config< healthMonitoring> node.

<healthMonitoring> contains heartBeatInterval which indicates number of seconds between raising WebHeartbeatEvent events.

Individual events contain minInterval attribute (works in similar fashion to heartBeatInterval).

To configure event and provider:

  1. Add eventMappings child element to healthMonitoring
  2. Add providers child element to healthMonitoring - indicate sthe health monitoring listeners.
  3. Add rules to healthMonitoring to associated web events and listeners

Don't need to register default web events and providers - done in servers configuration file. Only need to add rules to apps Web.config to turn these on. Note, need to know configured name of event class:

<system.web>

    <healthMonitoring enabled="true" heartbeatInterval="1">

        <rules>

            <add name="Heart Beat" eventName="Heartbeats" provider="EventLogProvider" profile="Default" />

        </rules>

    </healthMonitoring>

</system.web>

Download