Asp.net 2.0 caching and images

Discussion in 'ASP .Net' started by Alex Greenberg, Jan 13, 2006.

  1. Hi,

    I'm having a strange problem:

    I have a product.aspx page where the admin can change product
    properties, including the JPEG. The JPEG will always have the same
    name: eg. 120.jpg and in the same location.

    1) Admin visits page and browses to images/myimage.jpg
    2) Application takes myimage.jpg and creates a modified copy in
    myapp/img and calls it 120.jpg.
    3) image path in database changes to myapp/img/120.jpg
    3) Admin leaves page
    4) Admin revisits page (in same session) and picks a different image,
    which replaces the old one but retains the name 120.jpg.
    5) Admin leaves and comes back one more time. OLD IMAGE IS STILL
    DISPLAYED (from step 2). Even though image is changed on hard drive.

    obviously, IE is caching the image and going back to it on subsequent
    visits in same session. I tried using the No-Cache directive. I also
    added a ?t=<random> to the page parameters. Neither of these worked.

    Please help.
     
    Alex Greenberg, Jan 13, 2006
    #1
    1. Advertising

  2. Alex,

    Try adding the t=<random>

    To the image url instead of the page. IE caches images based on the image
    path not the page path. Making it look like the image path has changed will
    stop the caching. For example:

    http://msdn.microsoft.com/asp.net/art/asprk.jpg?t=1234

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Alex Greenberg" <> wrote in message
    news:...
    > Hi,
    >
    > I'm having a strange problem:
    >
    > I have a product.aspx page where the admin can change product
    > properties, including the JPEG. The JPEG will always have the same
    > name: eg. 120.jpg and in the same location.
    >
    > 1) Admin visits page and browses to images/myimage.jpg
    > 2) Application takes myimage.jpg and creates a modified copy in
    > myapp/img and calls it 120.jpg.
    > 3) image path in database changes to myapp/img/120.jpg
    > 3) Admin leaves page
    > 4) Admin revisits page (in same session) and picks a different image,
    > which replaces the old one but retains the name 120.jpg.
    > 5) Admin leaves and comes back one more time. OLD IMAGE IS STILL
    > DISPLAYED (from step 2). Even though image is changed on hard drive.
    >
    > obviously, IE is caching the image and going back to it on subsequent
    > visits in same session. I tried using the No-Cache directive. I also
    > added a ?t=<random> to the page parameters. Neither of these worked.
    >
    > Please help.
    >
     
    S. Justin Gengo [MCP], Jan 13, 2006
    #2
    1. Advertising

  3. Alex Greenberg

    Joerg Jooss Guest

    Hello S. Justin Gengo [MCP],

    > Alex,
    >
    > Try adding the t=<random>
    >
    > To the image url instead of the page. IE caches images based on the
    > image path not the page path. Making it look like the image path has
    > changed will stop the caching. For example:
    >
    > http://msdn.microsoft.com/asp.net/art/asprk.jpg?t=1234


    A better approach is to use HTTP CacheControl headers. Simply configure IIS
    to attach the HTTP header CacheControl: no-cache to all images served from
    your image directory.

    Cheers,
    --
    Joerg Jooss
     
    Joerg Jooss, Jan 16, 2006
    #3
  4. Thanks, I don't have control over the second approach, but the first
    one worked perfectly.

    Best,

    Alex
     
    Alex Greenberg, Jan 18, 2006
    #4
  5. Alex Greenberg

    grubar30

    Joined:
    Mar 10, 2008
    Messages:
    1
    awesome man.....thank you so much for this tip....I've spent hours/days trying to work out why my images were being cached by IE, inspite of the fact that I tried all the usual no-cache code (both HTML meta and ASP)

    you saved me dude....thank you heaps!!!!
     
    grubar30, Mar 10, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hypo
    Replies:
    6
    Views:
    421
  2. Troy Simpson

    Fragment Caching inside page caching?

    Troy Simpson, Jan 19, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    802
    Troy Simpson
    Jan 19, 2004
  3. Smokey Grindle

    Caching js and images on client

    Smokey Grindle, Jul 7, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    433
    John Timney \(MVP\)
    Jul 7, 2006
  4. JimLad
    Replies:
    3
    Views:
    924
    JimLad
    Jan 21, 2010
  5. CJM

    Caching images & ASP pages

    CJM, Jun 23, 2004, in forum: ASP General
    Replies:
    12
    Views:
    226
Loading...

Share This Page