Very frustrating caching issue...

R

rtmc

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
 
K

Ken Dopierala Jr.

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.
 
E

Eliyahu Goldin

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
 
R

rtmc

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
 
K

Kevin Spencer

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
 
K

Ken Dopierala Jr.

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.
 
T

Ted Harper

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.
 
R

rtmc

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top