根据URL更改OutputCache

Bla*_*rig 8 asp.net caching url-rewriting

我有一个页面,我想使用OutputCache指令缓存.但是,我使用URL重写器模块在此页面上引导多个URL,每个URL具有不同的内容.

有没有办法使用缓存输出每个URL?我没有其他标准可以改变缓存结果.

Bla*_*rig 11

最后,这很容易修复.

  1. 将以下指令添加到需要缓存的页面:

    <%@ outputcache duration ="600"location ="Downstream"varybyparam ="none"varybycustom ="RawURL"%>

  2. 将此方法添加到global.asax文件中

    public override string GetVaryByCustomString(HttpContext context, string custom)
    {
        switch (custom.ToUpper())
        {
            case "RAWURL":
                return context.Request.RawUrl;
    
            default:
                return "";
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)