title: Why is my MVC controller slow when serving images
body: <p>I have this MVC view that has a list of images, these images are dynamic so they come from a controller. To simplify things this controller has only this code:</p>
  
  <pre><code>    [OutputCache(Duration = 0, NoStore = true, Location = OutputCacheLocation.None)]
      public ActionResult RenderImage(int id)
      {
      return File(@"C:\Users\Pictures\myimage.png", "image/png");
      }
  </code></pre>
  
  <p>I'm not caching things to prove my point.</p>
  
  <p>My view requests 8 images all with a different id, and the timings are horrible:</p>
  
  <p><img src="https://i.stack.imgur.com/3T1J4.png" alt="timings"></p>
  
  <p>Sometimes it's fast for some images (which are all the same) and on each refresh it's different, can't find a pattern in it.</p>
  
  <p>The app is hosted in IIS and the timetaken in the server logs shows it's the server that is eating up the time:</p>
  
  <p><img src="https://i.stack.imgur.com/vBFXP.png" alt="enter image description here"></p>
  
  <p>Has anyone a clue why this happens? If I request the images individually (not in the page) it's always fast.</p>