Reputation: 9453
ASP.Net MVC 3 RTM. I am trying to use the OutputCache attribute in an action, but doesn't appear to be working. Here is the Http Request and Response.
Request URL:http://localhost/MyApp/Employee.mvc/GetImage?userId=myUserId Request Method:GET Status Code:200 OK Request Headers Accept:*/* Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3 Accept-Encoding:gzip,deflate,sdch Accept-Language:en-US,en;q=0.8 Cache-Control:no-cache Connection:keep-alive Cookie:ASP.NET_SessionId=sessionIdStuff Host:localhost Pragma:no-cache Referer:http://localhost/MyApp/Employee/Review/1/Index User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US)
AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.98 Safari/534.13 Query String Parameters userId:myUser Response Headers Cache-Control:private, no-store, max-age=3484
Content-Length:1428 Content-Type:image/jpeg Date:Wed, 16 Feb 2011 22:59:14 GMT Expires:Wed, 16 Feb 2011 23:57:19 GMT Last-Modified:Wed, 16 Feb 2011 22:57:19 GMT Server:Microsoft-IIS/5.1 Vary:* X-AspNet-Version:4.0.30319 X-AspNetMvc-Version:3.0 X-Powered-By:ASP.NET
Here is the controller:
[HttpGet, OutputCache(Location= OutputCacheLocation.Client, VaryByParam="userId", Duration=3600, NoStore=true)]
public FileContentResult GetImage(string userId)
{
byte[] result;
using (var client = new WebClient())
{
client.Credentials = CredentialCache.DefaultCredentials;
result = client.DownloadData(string.Format(IntranetUrl, userId));
}
return File(result, "image/jpeg");
}
and my View:
<img alt="Employee Picture" src='@Url.Action("GetImage", "Employee", new { userId = Model.UserId, area=""})' width="75px" height="100px" />
I tried comparing with other static images that are getting cached and the only differences where these lines:
Cache-Control:private, no-store, max-age=3484
This is included in my action, but not in the static images. Also, the static images had an ETag, but my action response did not.
Can anyone help why this might not be cached in the browser?
Thanks for any help..
Upvotes: 2
Views: 3814
Reputation: 1218
Try remove: NoStore=true (or set NoStore = false), and it'll work :)
Upvotes: 2