前段时间工作比较忙,没时间读代码,这几天有空,正好又来静读代码了.

Menus_ascx中我们看到用了缓存自定义字符串"authenticated"

<%@ OutputCache Duration="86400" VaryByParam="None" VaryByCustom="authenticated" %>
注意:
@OutputCache 指令与必需的 Duration 和 VaryByParam 属性包括在一起。必须将 Duration 属性设置为大于零的任意整数。如果不想使用 VaryByParam 属性提供的功能,请将其值设置为 None


 

Global.asax文件中重写GetVaryByCustomString方法

此处是根据用户是否验证来缓存用户控件,即一个通过验证的用户控件,一个未验证的用户控件

 1代码阅读总结之Fitch and Mather 7.0(自定义字符串缓存页)public override string GetVaryByCustomString(HttpContext context, string custom)
 2        }

 

根据此思路我们可以开发一个依浏览器类型不同的缓存页面的例子

例如我们现有页面WebForm3.aspx,我们可以根据访问着的浏览器类型来做页面缓存

首先在页面中加入

<%@ OutputCache Duration="600" VaryByParam="none" VaryByCustom="ietype" %>

如果定义了自定义字符串,必须在应用程序的 Global.asax 文件中重写 HttpApplication.GetVaryByCustomString 方法

 

 1代码阅读总结之Fitch and Mather 7.0(自定义字符串缓存页)public override string GetVaryByCustomString(HttpContext context, string custom)
 2        }

 

这样设置好后,

当我用IE6访问页面WebForm3.aspx时,服务器缓存这个类型浏览器的页面600秒

当我再用Opera7.54访问页面WebForm3.aspx时,服务器又缓存这个类型浏览器的页面600秒

相关文章:

  • 2021-07-15
  • 2022-12-23
  • 2021-12-30
  • 2022-12-23
  • 2021-12-29
  • 2022-02-24
  • 2022-12-23
猜你喜欢
  • 2022-01-24
  • 2022-12-23
  • 2021-06-20
  • 2022-02-19
  • 2021-07-04
  • 2021-11-14
  • 2022-12-23
相关资源
相似解决方案