首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> ASP.NET 基礎 >> 關於ASP.NET

程式碼閱讀總結:Fitch and Mather 7.0 - 自訂字串快取 (VaryByCustom)

     編輯:關於ASP.NET

使用 `<%@ OutputCache VaryByCustom="authenticated" %>` 依使用者驗證狀態分開快取使用者控件。

Global.asax 實作 GetVaryByCustomString

public override string GetVaryByCustomString(HttpContext context, string custom)
{
    if (context.Request.IsAuthenticated) return "B"; // 已驗證
    else return "C"; // 未驗證
}

擴展應用:依瀏覽器類型快取

頁面加入 `<%@ OutputCache Duration="600" VaryByParam="none" VaryByCustom="ietype" %>`,在 GetVaryByCustomString 中判斷 Request.Browser.Type 回傳不同字串,即可實現瀏覽器級別快取區隔。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved