I had to deal with this a lot, but I need to better understand the final goal, since IIS7 will update its cache if the image is changed on the server, so maybe what you see is the browser cache, have you looked to ethics?
An old fall back is to insert a random query string at the end of the image path, which makes the browser guess.
One surefire way to prevent it from caching is to create your own file handler for .gif, .jpg, .png extention (lookup iHttpHandler) (the code below is from http://www.codeguru.com/csharp/csharp/cs_network/http/article. php / c12641 /
using System.IO; using System.Web; using System.Globalization; namespace MVPHacks { public class ImageHandler: IHttpHandler { public void ProcessRequest(System.Web.HttpContext ctx) { HttpRequest req = ctx.Request; string path = req.PhysicalPath; string extension = null; string contentType = null; extension = Path.GetExtension(path).ToLower(); switch (extension) { case ".gif": contentType = "image/gif"; break; case ".jpg": contentType = "image/jpeg"; break; case ".png": contentType = "image/png"; break; default: throw new NotSupportedException("Unrecognized image type."); } if (!File.Exists (path)) { ctx.Response.Status = "Image not found"; ctx.Response.StatusCode = 404; } else { ctx.Response.StatusCode = 200; ctx.Response.ContentType = contentType; ctx.Response.WriteFile (path); } } public bool IsReusable { get {return true; } } } }
And don't forget to remove the default image handlers and add them to both sections of web.config
<httpHandlers> <clear /> <add verb="*" path="*.jpg" type="MVPHacks.ImageHandler" /> <add verb="*" path="*.gif" type="MVPHacks.ImageHandler" /> <add verb="*" path="*.png" type="MVPHacks.ImageHandler" /> </httpHandlers> <handlers> <clear /> <add verb="*" path="*.png" type="MVPHacks.ImageHandler" name="png" /> <add verb="*" path="*.gif" type="MVPHacks.ImageHandler" name="gif" /> <add verb="*" path="*.jpg" type="MVPHacks.ImageHandler" name="jpg /> </handlers>
source share