views:

23

answers:

1

There are lots of questions about how to force the browser to cache or not to cache any image. But, I am facing slightly different situation. In several places of my web page, I am using following code for the images.

<img title="<%= Html.Encode(Model.title)%>" 
  src="<%= Url.Action(MVC.FrontEnd.Actions.RetrieveImage(Model.SystemId))%>"/>

So, in the generated HTML it is like

<img title="blahblah" src="http://xyz.com/FrontEnd/Actions/RetrieveImage?imageId=X"&gt;

Where X is some integer. I have seen that though the browser (IE or Mozilla) caches images by default, it is not caching images generated by above method.

Is there any way I can tell browser to cache images of above type?

Thanks in advance.

A: 

In order to do this you can set the Expires and MaxAge headers of the response. To simplify things, you can create a custom ActionFilter.

Here's a good guide in how to achieve this: ASP.NET MVC Action Filter - Caching and Compression

Mickel
Thanks for the link.
Bipul