title: Cache images provided through script
body: <p>I have a script, which by using several querystring variables provides an image. I am also using URL rewriting within IIS 7.5.</p>
  
  <p>So images have an URL like this:
  <a href="http://mydomain/pictures/ajfhajkfhal/44/thumb.jpg" rel="nofollow noreferrer">http://mydomain/pictures/ajfhajkfhal/44/thumb.jpg</a>
  or
  <a href="http://mydomain/pictures/ajfhajkfhal/44.jpg" rel="nofollow noreferrer">http://mydomain/pictures/ajfhajkfhal/44.jpg</a></p>
  
  <p>This is rewritten to:
  <a href="http://mydomain/Picture.aspx?group=ajfhajkfhal&amp;id=44&amp;thumb=thumb.jpg" rel="nofollow noreferrer">http://mydomain/Picture.aspx?group=ajfhajkfhal&amp;id=44&amp;thumb=thumb.jpg</a>
  or
  <a href="http://mydomain/Picture.aspx?group=ajfhajkfhal&amp;id=44" rel="nofollow noreferrer">http://mydomain/Picture.aspx?group=ajfhajkfhal&amp;id=44</a></p>
  
  <p>I added caching rules to IIS to cache JPG images when they are requested. This works with my images that are REAL images on the disk. When images are provided through the script, they are somehow always requested through the script, without being cached.</p>
  
  <p>The images do not change that often, so if the cache at least is being kept for 30 minutes (or until file change) that would be best.</p>
  
  <p>I am using .NET/C# 4.0 for my website. I tried setting several cache options in C#, but I cant seem to find how to cache these images (client-side), while my static images are cached properly.</p>
  
  <p><strong>EDIT</strong> I use the following options to cache the image on the client side, where 'fileName' is the physical filename of the image (on disk).</p>
  
  <pre><code>context.Response.AddFileDependency(fileName);
  context.Response.Cache.SetETagFromFileDependencies();
  context.Response.Cache.SetLastModifiedFromFileDependencies();
  context.Response.Cache.SetCacheability(HttpCacheability.Public);
  context.Response.Cache.SetExpires(DateTime.Now.AddTicks(600));
  context.Response.Cache.SetMaxAge(new TimeSpan(0, 5, 0));
  context.Response.Cache.SetSlidingExpiration(true);
  context.Response.Cache.SetValidUntilExpires(true);
  context.Response.ContentType = "image/jpg";
  </code></pre>
  
  <p><strong>EDIT 2</strong> Thanks for pointing that out, that was indeed a very stupid mistake ;). I changed it to 30 minutes from now (DateTime.Now.AddMinutes(30)).</p>
  
  <p>But this doesnt solve the problem. I am really thinking the problem lies with Firefox. I use Firebug to track each request and somehow, I am thinking I am doing something fundamentally wrong. Normal images (which are cached and static) give back an response code "304 (Not Modified)", while my page always gives back a "200 (OK)".</p>
  
  <p><a href="http://images.depl0y.com/capture.jpg" rel="nofollow noreferrer">alt text http://images.depl0y.com/capture.jpg</a></p>