Very frustrating caching issue...

Discussion in 'ASP .Net' started by rtmc, Sep 21, 2004.

  1. rtmc

    rtmc Guest

    Can anyone help me with the following issue? I am STUCK. I'll make
    this as basic as I can... I have an ASP.Net admin page that allows
    users to post images to the server, and the images are displayed as
    thumbnails on the same page. So, if you post a new image for
    'Image1', the image is uploaded on button click, and the user then
    sees their image in the appropriate spot below. Clicking on the image
    fires off to a page that deletes the image, and the returns the to the
    upload page, where their image placeholder is now empty. So far, so
    good... Here's where my problem occurs - if I delete an image, and
    then add a new one right behind it, they keep the same name. (Has to
    be done this way). So, if I upload a picture of a football for 'Image
    1', it will save as image1.jpg. If I then delete it and add a new
    'Image 1' (say a basketball), it is the NEW image1.jpg.

    The issue occurs when I delete an image, and replace it. On postback,
    the OLD image is showing, even though the new image is what displays
    in the file structure. (Example - post football, delete football,
    post basketball, football is showing...) If I hit refresh, I then see
    the new image, but this is not acceptable. I need the new image to
    show immediately upon postback after uploading.

    There's the background - I am fairly certian this is a caching issue.
    I have:

    added : Response.Cache.SetCacheability(HttpCacheability.NoCache); to
    the PageLoad, with no luck.

    added: <%@ OutputCache Duration="1" Location="none" VaryByParam="none"
    %> to the aspx page in the header, with no luck.

    Shut down the computer and tried again, with no luck.

    Emptied my cache - no luck...

    Finally, I went to my Internet Options in IE and set pages to 'Check
    for Newer Versions of Stored Pages' every time - and this DID work.
    However, I can't tell all of my users to do this.

    So, I did get something to work, but that won't cut it. I need to
    somehow get the exact same functionality by using code. Everything I
    know of (mentioned above) is not working... Is there anyone out there
    who can help me out? I am at my wits end over this!!!!

    Thanks,

    Ryan
     
    rtmc, Sep 21, 2004
    #1
    1. Advertising

  2. Hi Ryan,

    Go into IIS, right click on your website (or better yet, just the folder in
    your website that holds the images) then click properties, click the HTTP
    Headers tab, check Enable Content Expiration, then click Expire Immediately.
    Good luck! Ken.

    --
    Ken Dopierala Jr.
    For great .Net web hosting try:
    http://www.webhost4life.com/default.asp?refid=Spinlight


    "rtmc" <> wrote in message
    news:...
    > Can anyone help me with the following issue? I am STUCK. I'll make
    > this as basic as I can... I have an ASP.Net admin page that allows
    > users to post images to the server, and the images are displayed as
    > thumbnails on the same page. So, if you post a new image for
    > 'Image1', the image is uploaded on button click, and the user then
    > sees their image in the appropriate spot below. Clicking on the image
    > fires off to a page that deletes the image, and the returns the to the
    > upload page, where their image placeholder is now empty. So far, so
    > good... Here's where my problem occurs - if I delete an image, and
    > then add a new one right behind it, they keep the same name. (Has to
    > be done this way). So, if I upload a picture of a football for 'Image
    > 1', it will save as image1.jpg. If I then delete it and add a new
    > 'Image 1' (say a basketball), it is the NEW image1.jpg.
    >
    > The issue occurs when I delete an image, and replace it. On postback,
    > the OLD image is showing, even though the new image is what displays
    > in the file structure. (Example - post football, delete football,
    > post basketball, football is showing...) If I hit refresh, I then see
    > the new image, but this is not acceptable. I need the new image to
    > show immediately upon postback after uploading.
    >
    > There's the background - I am fairly certian this is a caching issue.
    > I have:
    >
    > added : Response.Cache.SetCacheability(HttpCacheability.NoCache); to
    > the PageLoad, with no luck.
    >
    > added: <%@ OutputCache Duration="1" Location="none" VaryByParam="none"
    > %> to the aspx page in the header, with no luck.
    >
    > Shut down the computer and tried again, with no luck.
    >
    > Emptied my cache - no luck...
    >
    > Finally, I went to my Internet Options in IE and set pages to 'Check
    > for Newer Versions of Stored Pages' every time - and this DID work.
    > However, I can't tell all of my users to do this.
    >
    > So, I did get something to work, but that won't cut it. I need to
    > somehow get the exact same functionality by using code. Everything I
    > know of (mentioned above) is not working... Is there anyone out there
    > who can help me out? I am at my wits end over this!!!!
    >
    > Thanks,
    >
    > Ryan
     
    Ken Dopierala Jr., Sep 22, 2004
    #2
    1. Advertising

  3. Following someone's recomendation I am using the following 3 lines for
    solving caching problems:

    Response.ExpiresAbsolute = DateTime.Now.AddDays (-1);
    Response.Cache.SetCacheability (System.Web.HttpCacheability.NoCache);
    Response.AppendHeader ("Pragma", "no-cache");

    Not sure wich one of them does the trick, but the problem is solved.

    Eliyahu

    "rtmc" <> wrote in message
    news:...
    > Can anyone help me with the following issue? I am STUCK. I'll make
    > this as basic as I can... I have an ASP.Net admin page that allows
    > users to post images to the server, and the images are displayed as
    > thumbnails on the same page. So, if you post a new image for
    > 'Image1', the image is uploaded on button click, and the user then
    > sees their image in the appropriate spot below. Clicking on the image
    > fires off to a page that deletes the image, and the returns the to the
    > upload page, where their image placeholder is now empty. So far, so
    > good... Here's where my problem occurs - if I delete an image, and
    > then add a new one right behind it, they keep the same name. (Has to
    > be done this way). So, if I upload a picture of a football for 'Image
    > 1', it will save as image1.jpg. If I then delete it and add a new
    > 'Image 1' (say a basketball), it is the NEW image1.jpg.
    >
    > The issue occurs when I delete an image, and replace it. On postback,
    > the OLD image is showing, even though the new image is what displays
    > in the file structure. (Example - post football, delete football,
    > post basketball, football is showing...) If I hit refresh, I then see
    > the new image, but this is not acceptable. I need the new image to
    > show immediately upon postback after uploading.
    >
    > There's the background - I am fairly certian this is a caching issue.
    > I have:
    >
    > added : Response.Cache.SetCacheability(HttpCacheability.NoCache); to
    > the PageLoad, with no luck.
    >
    > added: <%@ OutputCache Duration="1" Location="none" VaryByParam="none"
    > %> to the aspx page in the header, with no luck.
    >
    > Shut down the computer and tried again, with no luck.
    >
    > Emptied my cache - no luck...
    >
    > Finally, I went to my Internet Options in IE and set pages to 'Check
    > for Newer Versions of Stored Pages' every time - and this DID work.
    > However, I can't tell all of my users to do this.
    >
    > So, I did get something to work, but that won't cut it. I need to
    > somehow get the exact same functionality by using code. Everything I
    > know of (mentioned above) is not working... Is there anyone out there
    > who can help me out? I am at my wits end over this!!!!
    >
    > Thanks,
    >
    > Ryan
     
    Eliyahu Goldin, Sep 22, 2004
    #3
  4. rtmc

    rtmc Guest

    Ken, thanks so much for your prompt response. Unfortunately, this
    didn't seem to fix the issue in my testing environment, and I'm not
    sure what kind of access I'll have on the folders in production. Any
    other ideas?

    Thanks again.

    Ryan
     
    rtmc, Sep 22, 2004
    #4
  5. Your only option is one you've ruled out: The file names need to be
    different.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    I get paid good money to
    solve puzzles for a living

    "rtmc" <> wrote in message
    news:...
    > Ken, thanks so much for your prompt response. Unfortunately, this
    > didn't seem to fix the issue in my testing environment, and I'm not
    > sure what kind of access I'll have on the folders in production. Any
    > other ideas?
    >
    > Thanks again.
    >
    > Ryan
     
    Kevin Spencer, Sep 22, 2004
    #5
  6. Hi Ryan,

    That is about all I can think of. It looks like you tried all the coding
    options. If changing the filename isn't viable then maybe you could store
    the uploaded file to SQL Server instead of to disk. Then when your page
    loads have it grab the image from the database. That should do the trick.
    Good luck! Ken.


    --
    Ken Dopierala Jr.
    For great .Net web hosting try:
    http://www.webhost4life.com/default.asp?refid=Spinlight

    "rtmc" <> wrote in message
    news:...
    > Ken, thanks so much for your prompt response. Unfortunately, this
    > didn't seem to fix the issue in my testing environment, and I'm not
    > sure what kind of access I'll have on the folders in production. Any
    > other ideas?
    >
    > Thanks again.
    >
    > Ryan
     
    Ken Dopierala Jr., Sep 22, 2004
    #6
  7. rtmc

    Ted Harper Guest

    On 21 Sep 2004 15:48:49 -0700, (rtmc) wrote:

    >I have an ASP.Net admin page that allows
    >users to post images to the server, and the images are displayed as
    >thumbnails on the same page. So, if you post a new image for
    >'Image1', the image is uploaded on button click, and the user then
    >sees their image in the appropriate spot below.

    ....
    >The issue occurs when I delete an image, and replace it. On postback,
    >the OLD image is showing, even though the new image is what displays
    >in the file structure. (Example - post football, delete football,
    >post basketball, football is showing...) If I hit refresh, I then see
    >the new image, but this is not acceptable. I need the new image to
    >show immediately upon postback after uploading.


    If the magic set of headers/flags posted elsewhere in this thread
    don't do the trick (and they certainly do for us with IE clients),
    maybe you could try - on the assumption you are building the IMG tags
    dynamically in your ASP.Net code - sticking a querystring parameter on
    the end of each with a random number in it.

    I haven't tried this (maybe it will fail on some/all browsers, it's
    just an off the wall suggestion that might fool the caching in the
    browsers) but what I mean is you just add some random "stuff" on the
    end when you are creating the image tags for your ASPX pages, so it
    ends up like (with a different random number affixed each time):

    <img src="something.jpg?xx=0.1223435" (etc)...>

    Obviously the parameter won't affect the image, but it SHOULD make the
    browser's cache see it as a different key (ie different from any
    something.jpg it already has cached) and thus fetch again from the
    server.

    Should work just fine too if you are serving the images via a
    gatekeeper page (eg as <img
    src="ImageServer.aspx?ImageName=something.jpg&xx=0.12345">), and again
    the idea is making the browser see it as a different image because of
    the varying querystring.

    ted.h.
    --
    Ted Harper (Sydney, Australia)
     
    Ted Harper, Sep 23, 2004
    #7
  8. rtmc

    rtmc Guest

    Thanks, Ted - this is exactly what I did, and it worked beautifully!
    I tried to post my solution on this thread earlier, but it looks like
    I gave it a new title and it is showing as a new thread. Oops....

    Anyway, the solution was indeed to append a random string at the end
    of each image. (Ex. - imgThumb.src = "images/thumb.jpg?random=" +
    RandomNumVar) This didn't impact the viewing of the image, but it did
    force the browser to go get the image everytime. Mission
    accomplished.

    Thanks to everyone for their time and suggestions!

    Ryan
     
    rtmc, Sep 23, 2004
    #8
    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. David Cho
    Replies:
    3
    Views:
    1,453
    Steve C. Orr [MVP, MCSD]
    Apr 7, 2005
  2. schnibitz

    Very Frustrating

    schnibitz, Jul 30, 2009, in forum: Perl Misc
    Replies:
    6
    Views:
    154
    schnibitz
    Jul 30, 2009
  3. J
    Replies:
    1
    Views:
    336
    Hans Mulder
    Jun 26, 2012
  4. Robert Kern

    Re: Frustrating circular bytes issue

    Robert Kern, Jun 26, 2012, in forum: Python
    Replies:
    0
    Views:
    214
    Robert Kern
    Jun 26, 2012
  5. Stefan Behnel

    Re: Frustrating circular bytes issue

    Stefan Behnel, Jun 26, 2012, in forum: Python
    Replies:
    0
    Views:
    203
    Stefan Behnel
    Jun 26, 2012
Loading...

Share This Page