前段时间工作比较忙,没时间读代码,这几天有空,正好又来静读代码了.
在Menus_ascx中我们看到用了缓存自定义字符串"authenticated"
<%@ OutputCache Duration="86400" VaryByParam="None" VaryByCustom="authenticated" %>
注意: @OutputCache 指令与必需的 Duration 和 VaryByParam 属性包括在一起。必须将 Duration 属性设置为大于零的任意整数。如果不想使用 VaryByParam 属性提供的功能,请将其值设置为 None
在Global.asax文件中重写GetVaryByCustomString方法
此处是根据用户是否验证来缓存用户控件,即一个通过验证的用户控件,一个未验证的用户控件
1public override string GetVaryByCustomString(HttpContext context, string custom)
3 // There are two different possible caching cases here so we return a different string in each one.
4 if(context.Request.IsAuthenticated)
6 // Request is authenticated
11 // Request is not authenticated
根据此思路我们可以开发一个依浏览器类型不同的缓存页面的例子
例如我们现有页面WebForm3.aspx,我们可以根据访问着的浏览器类型来做页面缓存
<%@ OutputCache Duration="600" VaryByParam="none" VaryByCustom="ietype" %>
如果定义了自定义字符串,必须在应用程序的 Global.asax 文件中重写 HttpApplication.GetVaryByCustomString 方法
1public override string GetVaryByCustomString(HttpContext context, string custom)
3 string browserType=context.Request.Browser.Type;
5 //custom自定义字符串,它指定哪个缓存的响应被用于响应当前请求
6 //有可能多个页面都定义了自定义字符串,这时可以依靠参数custom来具体区分
7 if ( custom=="ietype" )
8 if ( browserType=="IE6" )
12 if ( browserType=="Opera7" )
当我用IE6访问页面WebForm3.aspx时,服务器缓存这个类型浏览器的页面600秒
当我再用Opera7.54访问页面WebForm3.aspx时,服务器又缓存这个类型浏览器的页面600秒
A.Sql Server2005 Transact-SQL 新兵器学习
FlexAir开源版-全球免费多人视频聊天室,免费网络远程多人视频会议系统((Flex,Fms3联合开发))<视频聊天,会议开发实例8>
Sql Server2005 Transact-SQL 新兵器学习总结之-总结
sql server中分布式查询随笔(链接服务器(sp_addlinkedserver)和远程登录映射(sp_addlinkedsrvlogin)使用小总结)
ASP.NET2.0国际化/本地化应用程序的实现总结(多语言,多文化页面的实现)
自定义格式字符串随笔 (IFormattable,IFormatProvider,ICustomFormatter三接口的实现)
Mcad学习笔记之异步编程(AsyncCallback 委托,IAsyncResult接口,BeginInvoke方法,EndInvoke方法的使用小总结)
Mcad学习笔记之通过反射调用類的方法,屬性,字段,索引器(2種方法)
Mcad学习笔记之序列化(2进制和Soap序列 化)
Mcad学习笔记之委托再理解(delegate的构造器,BeginInvoke,EndInvoke,Invoke4个方法的探讨)
本文转自aierong博客园博客,原文链接:http://www.cnblogs.com/aierong/archive/2005/10/18/257144.html,如需转载请自行联系原作者