【发布时间】:2010-12-19 23:19:02
【问题描述】:
我有想要使用 OutputCache 指令缓存的页面。但是,我正在使用 URL 重写器模块在此页面上定向多个 URL,每个 URL 具有不同的内容。
有没有办法使用缓存每个 URL 的输出?没有其他标准可以让我改变缓存结果。
【问题讨论】:
标签: asp.net caching url-rewriting
我有想要使用 OutputCache 指令缓存的页面。但是,我正在使用 URL 重写器模块在此页面上定向多个 URL,每个 URL 具有不同的内容。
有没有办法使用缓存每个 URL 的输出?没有其他标准可以让我改变缓存结果。
【问题讨论】:
标签: asp.net caching url-rewriting
最后,这很容易解决。
在需要缓存的页面中添加如下指令:
将此方法添加到 global.asax 文件中
public override string GetVaryByCustomString(HttpContext context, string custom)
{
switch (custom.ToUpper())
{
case "RAWURL":
return context.Request.RawUrl;
default:
return "";
}
}
【讨论】:
您可以使用 Response.Cache 以编程方式设置缓存选项。您可以打开查询字符串变量,并根据具体情况适当地设置 Response.Cache 上的属性。
MSDN on Cache object
Another helpful article from aspalliance.com
【讨论】: