asp.net ¿Í»§¶Ë»º´æ(ClientCaching)
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();
}
private void StartClientCaching()
{
//Ö¸¶¨»º´æʱ¼ä
int secondsTime = 30;
string headers = Request.Headers["If-Modified-Since"];
long nowTicks=DateTime.Now.Ticks;
long modifiedTick = DateTime.Parse(Request.Headers["If-Modified-Since"]).Ticks;
long ticks = nowTicks - modifiedTick;
if (headers != null && TimeSpan.fromTicks(ticks).Seconds < secondsTime)
{
Response.Write(DateTime.Now);
Response.StatusCode = 304;
// ÕâÖÖ·½Ê½»á²úÉú“´Ë²Ù×÷ÒªÇóʹÓà IIS ¼¯³É¹ÜÏßģʽ¡£ ”µÄÒì³£
//Response.Headers.Add("Content-Encoding", "gzip");
// Response.Headers.Add ºÍ Response.AddHeader µ«ÊÇÔÚMSDNÖÐÃ÷ȷд³ö£¬ÕâЩ¶¼ÊÇΪÁ˼æÈÝASP£¬ÔÚ.NET 3.5ÒªÇóʹÓÃÏÂÃæÕâÖÖ·½Ê½¡£
//ÕâÖÖ·½Ê½²»»á³öÏÖÒì³£
Response.AppendHeader("Content-Encoding", "gzip");
Response.StatusDescription = "Not Madified";
}
else
{
Response.Write(DateTime.Now);
SetClientCaching(Response, DateTime.Now);
}
}
private void SetClientCaching(HttpResponse response, DateTime lastModified)
{
//½«ETag Http±êÍ·ÉèÖÃΪÖƶ¨×Ö·û´®
response.Cache.SetETag(lastModified.Ticks.ToString());
//½«Last_Modified Http±êÍ·ÉèÖÃΪÌṩµÄSystem.DateTimeÖµ
response.Cache.SetLastModified(lastModified);
//½«Cache-Control ±êÍ·ÉèÖÃΪSystem.Web.HttpCacheabilityÖµÖ®Ò»
response.Cache.SetCacheability(System
Ïà¹ØÎĵµ£º
1. BinÎļþ¼Ð
BinÎļþ¼Ð°üº¬Ó¦ÓóÌÐòËùÐèµÄ£¬ÓÃÓڿؼþ¡¢×é¼þ»òÕßÐèÒªÒýÓõÄÈκÎÆäËû´úÂëµÄ¿É²¿Êð³ÌÐò¼¯¡£¸ÃĿ¼ÖдæÔÚµÄÈκÎ.dllÎÄ ¼þ½«×Ô¶¯µØÁ´½Óµ½Ó¦ÓóÌÐò¡£
2. App_BrowserÎļþ¼Ð
¸Ã¿ÉÑ¡µÄÎļþ¼Ð°üº¬.browserÎļþ¡£.browserÎļþÃèÊöä¯ÀÀÆ÷(²»¹ÜÊÇÒƶ¯É豸ä¯ÀÀÆ÷£¬»¹ÊÇ̨ʽ»úä¯ÀÀÆ÷)µÄÌØ Õ÷ºÍ¹¦ÄÜ¡£
3. ......
ʹÓà SqlDataSource ¿Ø¼þÖ»ÐèºÜÉٵĴúÂë»òÎÞÐèÈκδúÂë¼´¿É´ÓÊý¾Ý¿âÖмìË÷Êý¾Ý¡£SqlDataSource ¿Ø¼þ¿ÉÓÃÓÚÈκξßÓйØÁª ADO.NET Ìṩ³ÌÐò£¨ÔÚÅäÖÃÎļþµÄ DbProviderFactories ½ÚÖÐÅäÖ㩵ÄÊý¾Ý¿â£¬°üÀ¨ Microsoft SQL Server¡¢Oracle¡¢ODBC »ò OLE DB Êý¾Ý¿â£¨Èç Microsoft Access£©¡£ÄúÔÚÅäÖÃʱָ¶¨ SqlDataSource ʹÓõ ......
SqlDataSource ¿Ø¼þ¿É¶ÔËü¼ìË÷¹ýµÄÊý¾Ý½øÐлº´æ£¬ÕâÑù¿ÉÒÔ±ÜÃâÔÙ´ÎÔËÐÐ×ÊÔ´ÏûºÄÁ¿½Ï´óµÄ²éѯ£¬´Ó¶øÌá¸ßÓ¦ÓóÌÐòµÄÐÔÄÜ¡£»º´æÖ÷ÒªÓÃÓÚÊý¾Ý±ä»¯²»Æµ·±µÄÇé¿ö¡£
´ËÍ⣬µ±Í¨¹ý System.Data.SqlClient Ìṩ³ÌÐòʹÓà SqlDataSource ¿Ø¼þʱ£¬¿ÉÒÔʹÓà SqlCacheDependency ¶ÔÏó¡£ÕâÑù¿Éʹ SqlDat ......
1. ʹÓÃQueryString±äÁ¿
QueryStringÊÇÒ»Öַdz£¼òµ¥µÄ´«Öµ·½Ê½£¬Ëû¿ÉÒÔ½«´«Ë͵ÄÖµÏÔʾÔÚä¯ÀÀÆ÷µÄµØÖ·À¸ÖС£Èç¹ûÊÇ´«µÝÒ»¸ö»ò¶à¸ö°²È«ÐÔÒªÇ󲻸߻òÊǽṹ¼òµ¥µÄÊýֵʱ£¬¿ÉÒÔʹÓÃÕâ¸ö·½·¨¡£µ«ÊǶÔÓÚ´«µÝÊý×é»ò¶ÔÏóµÄ»°£¬¾Í²»ÄÜÓÃÕâ¸ö·½·¨ÁË¡£ÏÂÃæÊÇÒ»¸öÀý×Ó£º
a.aspxµÄC#´úÂë
private void Button1_Click(object sen ......
×î½ü×öÒ»¸öÍøÕ¾£¬ÀïÃæÉæ¼°µ½¼¶ÁªµÄÎÊÌ⣨ÈçÊ¡-ÊУ¬Æ·ÅÆ-ÐͺŵÈ), ÎÒÓõÄÊÇDropDownListÀ´ÊµÏֵģ¬ÉèÖø¸¼¶µÄAutoPostBackÊôÐÔΪÕæ.È»ºóÔÚËüµÄSelectedIndexChanged()ʼþÀïдÏàÓ¦µÄ´úÂ룬ÕâÑù¾ÍÄÜʵÏÖ¼¶Áª¹Øϵ£¨µ±È»ÕâÀïҪעÒâIsPostBackµÄÎÊÌ⣩. ×öºÃÖ®ºóÓÃʱ·¢ÏÖÒ»¸ö·Ç³£²»Ë¬µÄÎÊÌ⣬ÄǾ ......