Lm th? no ?: C?i thi?n hi?u su?t c?a b? nh? ?m trang trong ASP.NET

D?ch tiu ? D?ch tiu ?
ID c?a bi: 315896 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

? Trang ny

TM T?T

Bi vi?t ny ch?ng t? lm th? no ? c?i thi?n hi?u su?t c?a ASP.NET cc ?ng d?ng c?a b? nh? ?m ton b? ASP.NET trang v?i cc @ OutputCache ch? th? trang. B?n c?ng c th? l @ OutputCache Trang ch? th? ? nh? cache ph?n c? th? c?a m?t ASP.L?I trang, m?c d bi vi?t ny khng ch?ng minh ny th?c hi?n.

Yu c?u

Danh sch sau v?ch ra ?c ? ngh? ph?n c?ng, ph?n m?m, c s? h? t?ng m?ng v gi d?ch v? m b?n c?n:
  • Microsoft Visual Studio.NET
  • Microsoft Internet thng tin my ch? (IIS) 4.0 ho?c Microsoft Internet Information Services (IIS) 5.0
Bi vi?t ny gi? ?nh r?ng b?n ? quen thu?c v?i cc ch? ? sau:
  • Cc ?ng d?ng web
  • Microsoft ASP.NET

M t? k? thu?t

Khi b?n nh? cache thng tin, b?n ?t cc thng tin trong b? nh?. B?nh th?ng, khi IIS nh?n ?c m?t yu c?u cho m?t trang, IIS l?n ?c trang t? ?a c?ng v sau g?i trang. i khi, IIS c th? t? ?ng lu tr? thng tin trong b? nh? ? c?i thi?n hi?u su?t. Cc @ OutputCache ch? th? cho php b?n gi? m?t trang trong b? nh?, th?m ch n?u trang khng ph h?p tiu ch II s? d?ng ? xc ?nh thng tin g? n n?m gi? trong b? nh?.

V d?, cc trang truy c?p c s? d? li?u ang ch?y l?i t?ng th?i gian b?n duy?t trang ? c ?c d? li?u m?i nh?t. Khi b?n s? d?ng cc @ OutputCache ch? th?, trang ?c t? ch?c trong b? nh? v?i cc k?t qu? c?a m?t truy v?n c s? d? li?u cho ?n khi ?c ch? ?nh th?i gian h?t h?n. V? v?y, b?n c th? s? d?ng cc @ OutputCache ch? th? ? trnh cu c s? d? li?u m?i khi ai duy?t ?n trang. i?u ny l r?t h?u ch cho d? li?u m khng thay ?i th?ng xuyn.

T?o m?t ASP.NET Web ?ng d?ng s? d?ng @ OutputCache

Trong ph?n ny, b?n t?o m?t ASP.NET Web ?ng d?ng s? d?ng cc @ OutputCache Trang ch? th? cho b? nh? cache trang cho m?t kho?ng th?i gian c? th?.
  1. Th?c hi?n theo cc b?c sau ? t?o ra m?t m?i ASP.NET Web ?ng d?ng trong Visual Basic.NET:
    1. M? ph?ng thu tr?c quan.NET.
    2. Trn cc Tp tr?nh n, i?m ?n M?i, sau b?m D an.
    3. Trong cc D? n m?i h?p tho?i h?p, b?m vo Visual Basic d? n d?i Cc lo?i d? n, sau b?m ASP.NET Web ?ng d?ng d?i Khun mu.
  2. Chuy?n sang HTML xem trong c?a s? WebForm1.aspx, v sau thm sau ch? th? ngay l?p t?c sau khi cc @ Trang ch? th?:
    <%@ OutputCache Duration="10" VaryByParam="none" %>
    						
    M? ny t?p h?p cc th?i gian th?c hi?n thu?c tnh c?a cc @ OutputCache ch? th? ?n 10 giy ? cho cc n?i dung trang ?c lu tr? trong 10 giy. Ngoi ra, cc VaryByParam thu?c tnh ny bao g?m m?t d?u ch?m ph?y ngn cch danh sch cc dy m b?n c th? s? d?ng b? ?m ?u ra d?a trn cc bi?n ng?i dng ?nh ngh?a khc nhau. Ch?c nng ny l v?t ra ngoi ph?m vi c?a bi vi?t ny, do , m? tr?c b? VaryByParam ? khng c.
  3. Trong ch? ? xem HTML c?a WebForm1.aspx, thm m? sau y gi?a khai m?c v b? m?c<form>Tags thm m?t<b00></b00></form>Nh?n hi?u ki?m sot ? cc h?nh th?c:
    <asp:Label>
    Last cached: <%Response.Write(Now())%>
    </asp:Label>
    						
    B?n dng nh?n ny ? hi?n th? th?i gian qua trang ? ?c n?p. Cc gi tr? trong nh?n ny ch? nn thay ?i m?t l?n m?i 10 giy, b?t k? bao nhiu l?n trang ?c lm m?i.
  4. Trn cc Tp tr?nh n, nh?p vo Lu.
  5. Trn cc Xy d?ng tr?nh n, nh?p vo Xy d?ng gi?i php.
  6. Nh?p chu?t ph?i vo trang v b?m Xem trong tr?nh duy?t. Thng bo m?t nh?n xu?t hi?n, m hi?n th? th?i gian hi?n nay.
  7. Lm m?i trang nhi?u l?n. Ch ? r?ng nh?n thay ?i ch? sau khi kho?ng 10 giy th?i gian h?t h?n.

Danh sch m? ?y ?

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1"%>
<%@ OutputCache Duration="10" VaryByParam="none" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <title>WebForm1</title>
        <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
        <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </head>
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
        <asp:Label>
            Last Cached: <%Response.Write(Now())%>
        </asp:Label>
        </form>
    </body>
</html>
				
LU ?: B?n c th? c?n ph?i s?a ?i cc K? th?a thu?c tnh trong d?ng m? l c?n thi?t ? tham kh?o tn c?a cc d? n c?a b?n v m?u Web, sau y:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1"%>
				
Cc m? hi?n nay gi? ?nh r?ng d? n c?a b?n ?c ?t tn WebApplication1 v r?ng h?nh th?c trang Web c?a b?n ?c ?t tn WebForm1.

Xc minh r?ng n ho?t ?ng

  1. M? nhi?u c?a s? tr?nh duy?t.
  2. Trong m?i c?a s?, duy?t trang .aspx c?a b?n l m?c d b?n l m?t ng?i dng cu?i. Nh?n th?y r?ng t?t c? cc c?a s? hi?n th? cng m?t lc trong th?i gian 10-th? hai, m?c d b?n ? khng duy?t trang cng m?t lc.
  3. Sau 10 giy, duy?t ?n ho?c lm m?i trang .aspx c?a b?n. Nh?n th?y r?ng t?t c? cc c?a s? C?p Nh?t th?i gian.



THAM KH?O

? bi?t thm chi ti?t, ch? ? sau Microsoft Web site:
ASP.T?i u ha m?ng
http://MSDN.Microsoft.com/Library/Default.asp?URL=/Library/en-US/cpguide/HTML/cpconaspoptimization.asp

ASP.NET b? nh? ?m tnh nng
http://msdn2.Microsoft.com/en-US/Library/xsbfdd8c (vs.71) .aspx

B? nh? ?m ASP.Cc trang m?ng
http://msdn2.Microsoft.com/en-US/Library/06bh14hk (vs.71) .aspx

@ OutputCache
http://msdn2.Microsoft.com/en-US/Library/hdxfb6cy (vs.71) .aspx

Thu?c tnh

ID c?a bi: 315896 - L?n xem xt sau cng: 27 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft ASP.NET 1.1
  • Microsoft ASP.NET 1.0
T? kha:
kbcaching kbhowtomaster kbio kbperformance kbwebforms kbmt KB315896 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:315896

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com