• 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.
  • Posts

    • Tech demos are a declaration of desire, an horizon for what they pretend to put on those boxes call consoles (i still laugh at the poor implementation of Hairworks in W3 when you compare it with the demos)...being made on UE5 doesn't give me any confidence considering how poorly it runs in those things, and CDPR is not a marvel in that aspect neither. And about the game, so far is non existent besides the cinematic trailer. If from the get go they have to justify the whys for the protagonist, you start your narrative with the left foot.
    • Seen a 5090 for just over $3,000 at Best Buy just a couple days ago. It wasn't the sticker price that made me laugh... it's knowing that, for now... that kind of investment that includes drivers that don't work, is a headache no one should have to shell out for. But.. it's not the first time Nvidia has choked on crappy drivers, won't be the last.. so, if you spent a pretty penny on the next gen, hang in there... sure they'll get it right some day here soon.
    • Because they and their 801 partners are hungry for your data, and the web is the best facilitator of everything privacy-violating in this day and age... They want all your non-microsoft account data going to microsoft's servers:
    • Sorry, I found your question odd, that's all 😅.
    • "LOL The IoT version is for embedded systems" LOL. The IoT version is for whatever you want, why are you so stuck up? It's just A NAME. Open your mind, buddy 😅. It's not a different version of Windows, only the licensing model and the support dates change, nothing else. "there no real reason to do that" Everyone has their reasons. You love to use Linux. Why? You have YOUR reasons. Other people will have theirs. I use Windows 11 and Linux on the side. Why? I have my reasons. "No security updates? Who cares!" Many people do, just not you. Why not use a supported OS instead of an unsupported one if you can? LOL. I find it odd that a person that loves Linux and choice/freedom so much has such a hard time understanding why people do things different than him.
  • Recent Achievements

    • First Post
      m10d earned a badge
      First Post
    • Conversation Starter
      DarkShrunken earned a badge
      Conversation Starter
    • One Month Later
      jrromero17 earned a badge
      One Month Later
    • Week One Done
      jrromero17 earned a badge
      Week One Done
    • Conversation Starter
      johnwin1 earned a badge
      Conversation Starter
  • Popular Contributors

    1. 1
      +primortal
      251
    2. 2
      snowy owl
      157
    3. 3
      +FloatingFatMan
      140
    4. 4
      ATLien_0
      140
    5. 5
      Xenon
      128
  • Tell a friend

    Love Neowin? Tell a friend!