Reading Trace Output


Now that we’ve talked about how to configure tracing, let’s walk through the information that is automatically gathered during page execution and displayed in the trace output.

Request Details

The request details constitute the top-level information about the request and include which encoding is used for the request and response, what time the request was made, the session ID, as well as which HTTP verb was used and the response status code.

Trace Information

The trace information section has granular information about what is happening during the page life cycle. The From First and From Last columns reveal how much time has elapsed from the time the request first started and how much time has elapsed from the last trace event.

Tip

Use the trace From Last column data to quickly narrow down long-running pieces of code. This is particularly useful in isolating performance issues.

Control Tree

The page itself is the top-level control in the control tree. All other server controls fall somewhere under the page. For example, in Figure 10-1, we see that the page analyzing Trace Hello.aspx contains an HtmlForm control and a LiteralControl. In this case, the LiteralControl has a render size of just 2 bytes, so it’s probably just carriage-return/newline white space. The Label and more literal elements are contained in the HtmlForm.

In addition to tracking the actual size rendered for each control in the tree, the size of the view state data being round-tripped between client and server is also reported. Having an idea of how much view state is being used can help you tailor your application to be more efficient. Databound controls, in particular, can contribute significantly to the size of the view state.

Cookies Collection

The Cookies collection shows both the cookies received from the browser for a particular request and any new cookies or updated cookie values returned. Unfortunately, Cookies doesn’t distinguish between the two types. Code Listing 10-3 simply increments the value of a cookie called MyCookie on each request. In the trace information from Code Listing 10-3, shown in the trace.axd output in Figure 10-3, we see two entries for MyCookie with values of 10 and 11.

Code Listing 10-3: Cookie.aspx

start example
 <script language="C#" runat="server" trace="true">
protected void Page_Load(object o, EventArgs e) {
HttpCookie outbound = new HttpCookie("MyCookie");

HttpCookie inbound = Request.Cookies["MyCookie"];
if(inbound != null) {
outbound.Value = (Int32.Parse(inbound.Value) + 1).ToString();
theLabel.Text = inbound.Value;
}
else {
outbound.Value = "1";
}
Response.Cookies.Add(outbound);
}
</script>
<asp:label runat="server"
Text="no cookie value received" />
end example

click to expand
Figure 10-3: Cookie.aspx page output

Headers Collection

The Headers collection is an enumeration of all of the HTTP headers sent by the browser. Note that the ASP.NET_SessionId cookie is explicitly removed from the Headers and Server Variables information because it is managed entirely by ASP.NET.

Note

You can distinguish between inbound and outbound cookie values by looking at the Cookie row in the Headers collection. The value from the Cookie header is the value sent by the client.

Server Variables

The server variables are the data that can be retrieved from the Web server about the request and the server environment. This can include information such as the physical path to the application directory unless the application is running at lower trust levels, which would prevent the display of some server variables.

Form Collection

When the HTTP verb used in the request is a POST instead of a GET, which is the case for postbacks, an additional category of trace information is collected and displayed. The Form collection lists the variable names and values for each piece of data posted to the server. This information is particularly useful in tracking exactly what values are coming from the client.




Microsoft ASP. NET Coding Strategies with the Microsoft ASP. NET Team
Microsoft ASP.NET Coding Strategies with the Microsoft ASP.NET Team (Pro-Developer)
ISBN: 073561900X
EAN: 2147483647
Year: 2005
Pages: 144

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net