Troubleshooting techniques for ASP.NET websites
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:
|Request Details||General details on request|
|Trace Information||Performance info related to page life-cycle events|
|Control Tree||Info on each control on page, e.g. size|
|Session State||Displays session variables|
|Application State||Displays application variables|
|Request Cookies||Displays request cookies passed to server|
|Response Cookies||Displays response cookies sent from server|
|Headers Collection||The HTTP headers sent to server by client|
|Form Collection||List of values posted back to server|
|QueryString Collection||List of values in query string|
|Server Variables||Displays 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
|Capture Tracing Information||enabled||Enables application tracing|
|Display Tracing Info On Individual Pages||pageOutput||When true trace info displayed directly on web page being traced|
|Display Trace Output For||localOnly||When 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 Order||traceMode||Sort trace output by time or category|
|Number of trace requests to cache||requestLimit||Number of records to hold in trace log|
|Select which trace results to cache||mostRecent||When 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:
<trace enabled="true" pageOutput="false" localOnly="false" mostRecent="true" />
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.
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 library provides Sys.Debug client-side namespace, includes assert, trace, clearTrace, traceDump and fail methods.
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.
|WebBaseEvent||Base class for web events|
|WebManagementEvent||Web events that contain application process information|
|WebHeartbeatEvent||Periodic event raising info about app at set intervals|
|WebRequestEvent||Contains web request info|
|WebApplicationLifetimeEvent||Raised when significant event occurs, e.g. start or shutdown|
|WebBaseErrorEvent||Error based events|
|WebErrorEvent||Provides info on error when occurs|
|WebRequestErrorEvent||Request data for request errors|
|WebAuditEvent||Creates audit (Security) events|
|WebSuccessAuditEvent||Raised when successful security operation occurs|
|WebAuthenticationSuccessAuditEvent||Provides info when successful user authentication occurs|
|WebFailureAuditEvent||Raised when failed security operation occurs|
|WebAuthenticationFailureAuditEvent||Raised when failed attempt at user authentication occurs|
|WebViewStateFailureAuditEvent||Raised 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> 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:
- Add eventMappings child element to healthMonitoring
- Add providers child element to healthMonitoring - indicates the health monitoring listeners.
- 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:
<healthMonitoring enabled="true" heartbeatInterval="1">
<add name="Heart Beat" eventName="Heartbeats" provider="EventLogProvider" profile="Default" />