0

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Liero
  • 25,216
  • 29
  • 151
  • 297
  • I am not sure if this will help you: http://stackoverflow.com/questions/15911356/setting-http-cache-control-headers-in-webapi – alltej Apr 15 '16 at 20:27
  • Can't use just use: [OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")] – MeTitus Apr 15 '16 at 21:21

0 Answers0