【发布时间】:2011-01-23 08:15:38
【问题描述】:
我想知道是否可以将输出缓存与查询字符串参数和会话参数一起使用。
我提供基于位置的内容,countryid 存储在 session 中,而 categoryid、pageindex 等其他参数存储在 querystring 中。
【问题讨论】:
我想知道是否可以将输出缓存与查询字符串参数和会话参数一起使用。
我提供基于位置的内容,countryid 存储在 session 中,而 categoryid、pageindex 等其他参数存储在 querystring 中。
【问题讨论】:
使用 VaryByCustom 可以根据您想要的几乎任何内容来改变输出缓存,并提供一个返回缓存键字符串的特殊函数。对于您的情况,请尝试这样的指令:
<%@ OutputCache Duration="30" VaryByParam="myParam" VaryByCustom="mySessionVar" %>
然后在 Global.asax 中,为您的应用程序覆盖 GetVaryByCustomString 函数:
public override string GetVaryByCustomString(HttpContext context, string arg)
{
if(arg == "mySessionVar" && Session["mySessionVar"] != null)
{
return Session["mySessionVar"].ToString();
}
return base.GetVaryByCustomString(context, arg);
}
【讨论】: