无论我做什么,我都无法从 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 检查时响应标头的样子:
缓存控制:必须重新验证,最大年龄 = 60 内容长度:24233
内容类型:图像/jpeg 日期:2013 年 4 月 14 日星期日 22:04:32 GMT
服务器:Microsoft-IIS/8.0 X-AspNet-版本:4.0.30319
X-Powered-By:ASP.NET
X-SourceFiles:=?UTF-8?B?Qzpcc291cmNlXFRydW5rXFRlc3RcYXBpXHRlc3RcMQ==?=
关于如何进行的任何想法?