开发者

IIS7 - Client side caching a .ashx file that already has no-cache data set

开发者 https://www.devze.com 2023-04-06 23:23 出处:网络
In IIS7, I have a .ashx file from a third party which sets caching headers to be no-cache,private I want this to be cached on the client so I have added the following code to the global.asax

In IIS7, I have a .ashx file from a third party which sets caching headers to be no-cache,private

I want this to be cached on the client so I have added the following code to the global.asax

void Application_EndRequest(object sender, EventArgs e)
{
    if (Request.Path.IndexOf("Script.ashx") > -1)
    {
      Response.Cache.SetCacheability(HttpCacheability.Public);
      Response.Cache.SetExpires(DateTime.Now.AddDays(7));
      Response.Cache.SetValidUntilExpires(true);
      Response.Cache.VaryByHeaders["Accept-Language"] = true;
    }
}

I would expect the resulting cache information to be public, Expires: Thu, 29 Sep 2011 开发者_运维百科16:06:27 GMT

Instead however I get the Franken-response of no-cache,public Expires: Thu, 29 Sep 2011 16:06:27 GMT

So the code is taking replacing the private with public as I want but it fails to replace the no-cache directive. Is it possible to replace the no-cache directive with this approach: if so what am I missing; if not what other approaches are there?


The above code fails in IIS7 Classic mode but the Integrated mode the code works as expected and produces sensible response headers. I assume this is due to the way that classic works similar to an ISAPI filter. I have switched to Integrated mode and this has solved the issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号