• 0

[ASP.NET][C#] Image caching


Question

Hi,

I have module that uploads an image in db as bytes and shows that image on a button click.

Problem is that if i update an image it takes few minutes before it updates. i believe its caching issue but i dont know how to fix it.

I am doing something like this

HtmlImage AppImg = (HtmlImage)(DetailsView1.FindControl("AppImage"));

 AppImg.Src = "~/ImageHandler.axd?table=xyz&column=abc&width=157&height=157&pk0=" + Page.Request.QueryString["AppID"];

Any help... ?

Thanks in advance.

Link to comment
https://www.neowin.net/forum/topic/774626-aspnetc-image-caching/
Share on other sites

3 answers to this question

Recommended Posts

  • 0

i have checked

http://localhost:62264/release1/ImageHandler.axd?table= .. .......

and image doesnot update immediately it take time on above URL as well.

I have tried these as well

Response.Cache.SetNoStore();

Response.Cache.SetNoServerCaching();

Response.Cache.SetCacheability(HttpCacheability.NoCache);

but no luck ...

  • 0

Hi,

Caching is great, but it can also be the bane of many developers!

I think most browsers cache images based on the image uri, not the page uri. An easy trick would be to quickly add another querystring item with a random value, e.g.:

http://localhost:62264/release1/ImageHandl......&z=43154

Making sure the value is different each page view will ensure the browser fetches the new image each time. Not ideal, but it works.

Other (more lower level changes) could include changing the Cache-Control header to no-cache for a specific directory on the webserver itself.

  • 0

No luck with adding random string as well ... still not updating. i have tried to add in one browser .. login using another browser and then tried to check image was same and not updated in both browser. so its server side caching.. tried whatever i knew to disable server side caching but no luck

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.