Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (569.46 KB, 28 trang )
<span class='text_page_counter'>(1)</span><div class='page_container' data-page=1>
Exploring ASP.NET / Session 21 / 2 of 28
Exploring ASP.NET / Session 21 / 3 of 28
Exploring ASP.NET / Session 21 / 4 of 28
Exploring ASP.NET / Session 21 / 5 of 28
Exploring ASP.NET / Session 21 / 6 of 28
Exploring ASP.NET / Session 21 / 7 of 28
<% @Page Trace="True" TraceMode="SortByCategory" %>
<html>
<head>
<title>Page level Tracing</title>
</head>
<body>
<h1>A Program to test Trace...</h1>
</body>
</html>
Exploring ASP.NET / Session 21 / 8 of 28
<b>Request Details </b> <b>Lists all the information of the request </b>
<b>Trace Information </b> <b>Lists information from standard and </b>
<b>custom trace statements </b>
<b>Control Tree </b> <b>Lists all of the items in the page </b>
<b>Cookies Collection </b> <b>Lists all of the cookies of the page with </b>
<b>their values </b>
<b>Header Collection </b> <b>Lists all the items of the HTTP header </b>
<b>Form Collection </b> <b>Lists all of the form elements and their </b>
<b>values being POSTed. </b>
Exploring ASP.NET / Session 21 / 9 of 28
<% @ Page Trace="True" TraceMode="SortByTime" %>
<html>
<head>
<title>Trace Methods</title>
</head>
<body>
<script language="C#" runat="server">
void Page_Init()
{
Trace.Warn ("Page Init Event: Message
from Page Init");
}
void Page_Load(Object Sender, EventArgs E)
{
Exploring ASP.NET / Session 21 / 10 of 28
</script>
<h1>A Program to test Trace...</h1>
</body>
Exploring ASP.NET / Session 21 / 11 of 28
Exploring ASP.NET / Session 21 / 12 of 28
Exploring ASP.NET / Session 21 / 13 of 28
<configuration>
<system.web>
<b><trace enabled=“true” pageOutput=“true” /> </b>
</system.web>
</configuration>
Once this is coded, every
page will display trace
information.
Trace.axd file in the
application root directory
displays the information
Exploring ASP.NET / Session 21 / 14 of 28
<b>Parameter</b> <b>Description</b> <b>Default Value</b>
requestLimit Sets the number of trace requests to store
on the server 10
traceMode Sets whether the statistics should be
arranged according to time or category
(takes in value sortByCategory or
sortByTime)
sortByTime
pageOutput Sets whether the trace information is to
be displayed at the bottom of every page
(takes in either true or false)
False
Enabled Sets whether application level tracing is to
be enabled. (takes in values true or false) True
localOnly Sets whether Tracing is enabled for
Exploring ASP.NET / Session 21 / 15 of 28
Exploring ASP.NET / Session 21 / 16 of 28
After configuring the application
for debug mode, the application
needs to be invoked by requesting
one of the application pages
After requesting a page, the
debugger has to be launched by
typing DbgClr.exe in the Run
Exploring ASP.NET / Session 21 / 17 of 28
After invoking the debugger, the ASP.NET source file that needs to be debugged
should be opened
The next step is to open the Processes dialog box, by clicking on the Tools
menu, and then clicking on Debug processes. The show system processes option
should be checked. The Aspnet_wp.exe process should also be attached.
To set a breakpoint in an ASP.NET page, the left-hand margin on a line
containing an executable statement or method has to be clicked
A red dot appears where the breakpoint is set.
Moving the mouse over the breakpoint facilitates ensuring that the breakpoint,
is appropriately mapped to the correct application instance in the
The <b>Watch </b>window can be used to see the intrinsic objects on the page, like
Exploring ASP.NET / Session 21 / 18 of 28
Exploring ASP.NET / Session 21 / 19 of 28
Exploring ASP.NET / Session 21 / 20 of 28
<b><%@ </b>OutputCache Duration="120<b>" </b>VaryByParam="none"<b> %></b>
<html>
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs E)
{
TimeGen.Text = DateTime.Now.ToString ("G");
}
</script>
<body>
<h1>Use of Output Cache</h1>
<p><i>This page was generated on:</i>
<asp:label id="TimeGen" runat="server"/>
</body>
Exploring ASP.NET / Session 21 / 21 of 28
More flexibility and control can be provided to the ASP.NET applications, by even
programmatically setting the duration of the cache
This can be achieved by importing the System.Web.HttpCachePolicy class, from
which the SetExpires(DateTime) method can be used.
Response.Cache.SetExpires(DateTime.Now.AddSeconds(120));
Another caching method is called <b>Sliding Expiration</b>, where the expiration
period is renewed by the value specified every time the page is accessed.
To make this sliding expiration policy, where the expiration time out resets each
time the page is requested, the SlidingExpiration property (of the class) can be
set as follows
Exploring ASP.NET / Session 21 / 22 of 28
Exploring ASP.NET / Session 21 / 23 of 28
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<title>Caching Data</title>
</head>
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs e)
{
DataView mySource;
<b>mySource = (DataView) Cache ["MyCache"]; </b>
<b>if (mySource == null) </b>
<b>{</b>
SqlConnection myConnection = new SqlConnection
("server=SQLDB; database=Northwind; uid=sa; pwd =password");
Exploring ASP.NET / Session 21 / 24 of 28
SqlDataAdapter myCommand = new SqlDataAdapter ("select * from
customers", myConnection);
DataSet myds = new Dataset();
myCommand.Fill(myds, "employee");
mySource = new DataView (myds.Tables["employee"]);<b> </b>
<b> Cache ["MyCache"] = mySource; </b>
<b> CacheMsg.Text = "Dataset created from Table";</b>
}
else
{
<b> </b> <b> CacheMsg.Text = "Dataset retrieved from Cache"; </b>
}
MyDataGrid.DataSource =mySource;
MyDataGrid.DataBind();
}
Exploring ASP.NET / Session 21 / 25 of 28
<body>
<form method="GET" runat="server">
<h3><font face="Verdana">Caching Data</font></h3>
<ASP:DataGrid id="MyDataGrid" runat="server" />
<p>
<i><asp:label id="CacheMsg" runat="server"/></i>
</form>
Exploring ASP.NET / Session 21 / 27 of 28
Exploring ASP.NET / Session 21 / 28 of 28
The process of locating errors in the code is known as tracing.
Tracing in ASP.NET is provided in two levels:
Page-Level Tracing
Application Level tracing
Page Level Tracing displays a huge amount of information ranging from the timing when
each event was fired, to the timing when the cookies were created.
Application level tracing by default turns on page level tracing for all the pages in the
application.
The .NET Framework SDK includes a lightweight debugger that is perfectly suited for
debugging.
Caching is a technique used to increase performance by keeping frequently accessed data
in the memory.ASP.NET supports two types of caching, they are: