【发布时间】:2013-04-06 23:04:45
【问题描述】:
无论我做什么,我都无法从 web api 缓存中获取返回的图像,每次我请求图像时都会看到对服务器的请求。
我已经为标题设置尝试了许多 permiations,这是我最近的努力:
public class TestController : ApiController
{
public HttpResponseMessage Get(int id)
{
HttpResponseMessage response = new HttpResponseMessage();
StreamContent streamContent = new StreamContent(File.Open("c:\\1.jpg", FileMode.Open, FileAccess.Read, FileShare.Read));
response.Content = streamContent;
response.Content.Headers.Add("Content-Type", "image/jpeg");
response.Headers.CacheControl = new CacheControlHeaderValue
{
MustRevalidate = true,
Private= false,
MaxAge = TimeSpan.FromMinutes(1),
};
//string hash = new Guid("524DF956-D67A-4D66-A3E0-5E78726A204A").GetHashCode().ToString();
//response.Headers.ETag = new EntityTagHeaderValue(String.Concat("\"", hash, "\""), true);
//response.Content.Headers.LastModified = new DateTimeOffset(new DateTime(2012, 12, 24));
//response.Content.Headers.Expires = new DateTimeOffset(new DateTime(2013, 12, 24));
return response;
}
这就是我使用 chrome 检查时响应标头的样子:
Cache-Control:must-revalidate, max-age=60 Content-Length:24233
内容类型:image/jpeg 日期:2013 年 4 月 14 日星期日 22:04:32 GMT
服务器:Microsoft-IIS/8.0 X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
X-SourceFiles:=?UTF-8?B?Qzpcc291cmNlXFRydW5rXFRlc3RcYXBpXHRlc3RcMQ==?=
关于如何进行的任何想法?
【问题讨论】:
标签: asp.net-web-api httpresponse http-status-code-304 image-caching