2010-03-22 54 views

回答

1

在UserControl上創建一個公共屬性,您可以使用它來更改高速緩存的持續時間。

public Double CacheDuration { get; set; } 

     protected void Page_Load(object sender, EventArgs e) 
     { 
      Response.Cache.SetCacheability(HttpCacheability.Server); 
      Response.Cache.SetExpires(DateTime.Now + TimeSpan.FromSeconds(CacheDuration)); 
      Response.Write(DateTime.Now.ToString()); 
     } 

然後當你添加UserControl時,我的名字叫做Cached,你可以這樣做。

var cachedUserControl = new Cached {CacheDuration = 5}; 
      Page.Controls.Add(cachedUserControl); 
+0

輸出高速緩存默認設置公共,而不是服務器 - > Response.Cache.SetCacheability(HttpCacheability.Public) – kape123 2011-07-06 20:13:53

相關問題