I have an actionmethod that returns a File and has only one argument (an id).
e.g.
public ActionResult Icon(long id)
{
return File(Server.MapPath("~/Content/Images/image" + id + ".png"), "image/png");
}
I want the browser to automatically cache this image the first time I access it so the next time it doesn't have to download all the data.
I have tried using things like the OutputCacheAttribute and manually setting headers on the response. i.e:
[OutputCache(Duration = 360000)]
or
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetExpires(Cache.NoAbsoluteExpiration);
But the image is still loaded every time I hit F5 on the browser (I'm trying it on Chrome and IE). (I know it is loaded every time because if I change the image it also changes in the browser).
I see that the HTTP response has some headers that apparently should work:
Cache-Control:public, max-age=360000
Content-Length:39317
Content-Type:image/png
Date:Tue, 31 Jan 2012 23:20:57 GMT
Expires:Sun, 05 Feb 2012 03:20:56 GMT
Last-Modified:Tue, 31 Jan 2012 23:20:56 GMT
But the request headers have this:
Pragma:no-cache
Any idea on how to do this?
Thanks a lot