ASP.NET 2.0»º´æ (ת)
Ò»¡¢Ò³Êä³ö»º´æ
1.ÉèÖà ASP.NET Ò³»º´æµÄÁ½ÖÖ·½Ê½
1.1 ÒÔÉùÃ÷·½Ê½ÉèÖà ASP.NET Ò³µÄ»º´æ
ÒÔÉùÃ÷·½Ê½ÉèÖà ASP.NET Ò³µÄ»º´æµÄ·½·¨ÊÇÔÚÒ³ÖÐʹÓà @ OutputCache Ö¸ÁËüµÄ³£ÓÃÊôÐÔÈçÏ£º
³ÌÐò´úÂë
<%@ OutputCache Duration="" VaryByParam="" VaryByControl="" VaryByHeader="" VaryByCustom="" CacheProfile="" Location="" %>
Duration£ºÉèÖûº´æµ½ÆÚʱ¼ä£¬µ¥Î»£ºÃë¡£
VaryByParam£º¿ÉÓÃÀ´Ê¹»º´æÊä³öÒò²éѯ×Ö·û´®¶øÒ죬¶à¸ö²éѯ×Ö·ûÓ÷ֺŸô¿ª¡£
VaryByControl£º¿ÉÓÃÀ´Ê¹»º´æÊä³öÒò¿ØÖÆÖµ¶øÒì¡£
VaryByHeader£º¿ÉÓÃÀ´Ê¹»º´æÊä³öÒòÇëÇóµÄ HTTP ±êÍ·¶øÒì¡£
VaryByCustom£º¿ÉÓÃÀ´Ê¹»º´æÊä³öÒòä¯ÀÀÆ÷ÀàÐÍ»òÄú¶¨ÒåµÄ×Ô¶¨Òå×Ö·û´®¶øÒì¡£
CacheProfile£º½áºÏÅäÖÃÎļþʹÓá£
Location£ºÉèÖÃÒ³µÄ¿É»º´æÐÔ£¬ÖµÓÐAny,Client,Downstream,None,Server,ServerAndClient¡£
×¢£ºÔÚʹÓà @ OutputCache Ö¸Áîʱ£¬±ØÐë°üÀ¨Ò»¸ö VaryByParam ÊôÐÔ£¬·ñÔò½«³öÏÖ·ÖÎöÆ÷´íÎó¡£Èç¹û²»Ï£ÍûʹÓà VaryByParam ÊôÐÔÌṩµÄ¹¦ÄÜ£¬Ç뽫ËüµÄÖµÉèÖÃΪ“None”¡£
@ OutputCache Ö¸ÁîʹÓÃʾÀý
¢ÙʹÓòÎÊý¶ÔÒ³µÄ¸÷¸ö°æ±¾½øÐлº´æ£º
³ÌÐò´úÂë
<%@ OutputCache Duration="60" VaryByParam="City" %>
×¢£ºÈç¹ûÒª¸ù¾Ý¶à¸ö²ÎÊý¸Ä±äÊä³ö»º´æ£¬Çë°üÀ¨ÒԷֺŠ(;) ×÷Ϊ·Ö¸ô·ûµÄ²ÎÊýÃû³ÆµÄÁÐ±í£»Èç¹ûÒª¸ù¾ÝËùÓеIJÎÊýÖµÀ´¸Ä±ä»º´æ£¬Ç뽫VaryByParam ÊôÐÔÉèÖÃΪÐǺŠ(*)£»Èç¹û²»Òª¸ù¾Ý²ÎÊýÖµÀ´¸Ä±ä»º´æ£¬Ç뽫 VaryByParam ÊôÐÔÉèÖÃΪ"None"¡£
¢ÚʹÓà HTTP ±êÍ·¶ÔijҳµÄ¸÷¸ö°æ±¾½øÐлº´æ£º
³ÌÐò´úÂë
<%@ OutputCache Duration="60" VaryByParam="None" VaryByHeader="Accept-Language" %>
×¢£ºÈç¹ûÒª¸ù¾Ý¶à¸ö±êÍ·¸Ä±ä»º´æµÄÄÚÈÝ£¬ÇëÒԷֺŠ(;) ×÷Ϊ·Ö¸ô·û°üÀ¨±êÍ·Ãû³ÆµÄÁÐ±í£»Èç¹ûÒª¸ù¾ÝËùÓбêÍ·Öµ¸Ä±ä»º´æµÄÄÚÈÝ£¬Ç뽫VaryByHeader ÊôÐÔÉèÖÃΪÐǺŠ(*)¡£
¢ÛʹÓÃÇëÇóä¯ÀÀÆ÷»º´æÒ³µÄ¸÷¸ö°æ±¾£º
³ÌÐò´úÂë
<%@ OutputCache Duration="10" VaryByParam="None" VaryByCustom="browser" %>
¢ÜʹÓÃ×Ô¶¨Òå×Ö·û´®¶ÔÒ³µÄ¸÷¸ö°æ±¾½øÐлº´æ£º
³ÌÐò´úÂë
<%@ OutputCache Duration="10" VaryByParam="None" VaryByCustom="minorversion" %>
×¢£º»¹ÒªÔÚÓ¦ÓóÌÐòµÄ Global.asax ÎļþÖУ¬ÖØд GetVaryByCustomString ·½·¨ÒÔÖ¸¶¨×Ô¶¨Òå×Ö·û´®µÄÊä³ö»º´æÐÐΪ¡£²Î¿¼£ºhttp://msdn2.microsoft.com/zh-cn/
Ïà¹ØÎĵµ£º
1. ÓÃResponse.Write·½·¨
¡¡¡¡´úÂëÈçÏ£º
Response.Write("<script type='text/javascript'>alert("XXX");</script>");
´Ë·½·¨È±ÏݾÍÊDz»Äܵ÷Óýű¾ÎļþÖеÄ×Ô¶¨ÒåµÄº¯Êý£¬Ö»Äܵ÷ÓÃÄÚ²¿º¯Êý£¬¾ßÌåµ÷ÓÃ×Ô¶¨ÒåµÄº¯ÊýÖ»ÄÜÔÚResponse.WriteдÉϺ¯Êý¶¨ Ò壬±ÈÈç
Response.Write("<script type='tex ......
×î½ü×öÒ»¸öÍøÕ¾£¬ÀïÃæÉæ¼°µ½¼¶ÁªµÄÎÊÌ⣨ÈçÊ¡-ÊУ¬Æ·ÅÆ-ÐͺŵÈ), ÎÒÓõÄÊÇDropDownListÀ´ÊµÏֵģ¬ÉèÖø¸¼¶µÄAutoPostBackÊôÐÔΪÕæ.È»ºóÔÚËüµÄSelectedIndexChanged()ʼþÀïдÏàÓ¦µÄ´úÂ룬ÕâÑù¾ÍÄÜʵÏÖ¼¶Áª¹Øϵ£¨µ±È»ÕâÀïҪעÒâIsPostBackµÄÎÊÌ⣩. ×öºÃÖ®ºóÓÃʱ·¢ÏÖÒ»¸ö·Ç³£²»Ë¬µÄÎÊÌ⣬ÄǾ ......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
StartClientCaching();
......
Íøҳʼþ
µäÐ͵ÄʹÓ÷½Ê½
PreInit
PreInitʼþÊÇÍøÒ³ÉúÃüÖÜÆÚÖзdz£ÔçÆðµÄÒ»¸öʼþ£¬ÔÚPreInitʼþ´¥·¢Ö®ºó£¬¾Í»á¼ÓÔØÓû§ÉèÖÃÐÅÏ¢ÓëÍøÒ³Ö÷Ìâ¡£ÎÒÃÇͨ³£Ê¹ÓÃPreInitʼþÀ´Ö´ÐÐÏÂÁд¦Àí£º
l ¼ì²éIsPostBackÊôÐÔ£¬À´È·ÈÏÍøÒ³ÊÇ·ñΪµÚÒ»´Î±»´¦Àí¡£
l   ......