我有以下WebApi操作
public class MyController : ApiController
{
public HttpResponseMessage Get(int id)
{
var path = $"C:\\temp\\images\\{id}.png";
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
var stream = new FileStream(path, FileMode.Open);
result.Content = new StreamContent(stream);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
result.Content.Headers.Expires = DateTimeOffset.Now.AddDays(-1);
result.Headers.CacheControl = new CacheControlHeaderValue
{
NoCache = true,
Public = false,
Private = true
};
return result;
}
我通过动态地将这个img html元素附加到我的html文档来调用webapi:
<img src="http://localhost/api/mycontroller/5" />
但是,浏览器显示缓存的图像。