WebControl/Cache-Control question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am new to WebControls, I have created a WebControl that is used to present
an image, the image bing presented is created on runtime, each client side
button click causes the image to change, this require to prevent this image
from being cached, I have tried to play around with:
Context.Response.AddHeader("Cache-Control", ... )
and with
Context.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache)
BUT Still, the image is being extracted from the cache and the changes
cannot be seen...

What am I doing wrong here?
How can I prevent the image from being cached?

Any help, samples or pointers will be appreciated.
 
Nadav said:
How can I prevent the image from being cached?

What you describe sounds like the correct means of preventing caching by
the user agent, provided the user agent understands the header.

The only thing I'd check is that you're setting this on the correct HTTP re-
sponse, that is, the one generating the dynamic image (i.e., I presume else-
where in the same web control you're also setting the HTTP Content-Type
header to something like image/png or something.) The cache-control
won't apply to the image if you're setting it on the HTTP response for the
page as a whole, or if the image is just an <IMG SRC="myimage.png" />
tag that's been rendered. In this situation, the user agent makes two requests,
one to grab your page containing the <IMG> tag, and then a second request
for the .png file specified in that <IMG> tag. If you set cache-control on the
page to expire immediately, then that doesn't affect the request/response for
the .png file directly (because that response doesn't have a cache-control on
it). I'm only speculating about what your situation looks like here, it's really
two entirely different scenarios: (a) a WebForm producing a dynamic image
with Content-Type: image/png (or other graphics file format), vs. (b) a Web-
Form with a WebControl producing an <IMG SRC="myimage.png"/> tag
where the browser makes a second request that's separate to fetch the image.

One tool that you may try is the power toy, Fiddler, described in this article
and a free download from MSDN,

http://msdn.microsoft.com/ie/default.aspx?pull=/library/en-us/dnwebgen/html/ie_introfiddler.asp

Check that the browser is receiving the Cache-Control HTTP header on the
request for the image.

Another place to check potentially are the IIS logs which you can usually find in the,

C:\WINDOWS\SYSTEM32\LOGFILES\W3SVC1

directory on the web server. If the request coming in for the image was responded
to with an HTTP Status Code 304, then IIS told the browser that the image
requested hasn't changed (based on its timestamp) and the browser should get
it from its cache.


Derek Harmon
 
BUT Still, the image is being extracted from the cache >and the changes
cannot be seen...
I don't understand what you are trying to do. Please explain some more. Are
you trying to cache the control or not? Why do you need to uncache on each
client click?

setcachability is being passed the wrong param. you need to pass nocache on
server and client. (don't remember which setting it is off the top of my
head)

--
Regards,
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
_________________________
 
Back
Top