I have following WebApi action
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;
}
I call the webapi by dynamically appending this img html element to my html document:
<img src="http://localhost/api/mycontroller/5" />
However, the browser shows cached image.