[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.caching

Controlling the browser cache from an ASPX page

Grant Davis

5/4/2006 10:46:00 PM

I have an aspx page that is used in src tags on other pages to serve
images. The image that is served is determined by a query string:

src=mypage.aspx?imageId=12344

Each image has a unique id, so a unique image is defined by the entire
URL, including the query parameters.

The aspx page locates the file (wherever it may be) and puts it into
the output stream via Response.WriteFile().

Everything works great.

However, I would like to enable browser caching of these images and
only serve the image back to the browser if the file has changed (which
they sometimes do).

Because I cannot predict when the images will change, I would like the
server to respond with a "304 - Not Modified" if the file has not been
modified, and to serve it to the browser otherwise. I've read
everything I can find on the net about this scenario, but none of the
explainations are very clear and those suggesttions that I have tried
don't seem to work.

Could someone provide a simple, direct answer outlining how this can be
accomplished in asp.net 1.1?

Thanks in advance for your help.

Grant

2 Answers

Greg Young

5/5/2006 9:56:00 AM

0

A few things ...

1) why not just generate a new id on update? This would completely prevent
this issue.
2) It is quite easy to do .. just set Response.StatusCode and
Response.StatusDescription.

http://www.motobit.com/tips/detpg_net-last... includes an example.

Cheers,

Greg
"Grant Davis" <gdavis@elementum-inc.com> wrote in message
news:1146782788.925367.237720@y43g2000cwc.googlegroups.com...
>I have an aspx page that is used in src tags on other pages to serve
> images. The image that is served is determined by a query string:
>
> src=mypage.aspx?imageId=12344
>
> Each image has a unique id, so a unique image is defined by the entire
> URL, including the query parameters.
>
> The aspx page locates the file (wherever it may be) and puts it into
> the output stream via Response.WriteFile().
>
> Everything works great.
>
> However, I would like to enable browser caching of these images and
> only serve the image back to the browser if the file has changed (which
> they sometimes do).
>
> Because I cannot predict when the images will change, I would like the
> server to respond with a "304 - Not Modified" if the file has not been
> modified, and to serve it to the browser otherwise. I've read
> everything I can find on the net about this scenario, but none of the
> explainations are very clear and those suggesttions that I have tried
> don't seem to work.
>
> Could someone provide a simple, direct answer outlining how this can be
> accomplished in asp.net 1.1?
>
> Thanks in advance for your help.
>
> Grant
>


Grant Davis

5/5/2006 2:29:00 PM

0

Greg,

The id's tie the files to records in a database, so they can't easily
be changed.

I actually have gotten things working by checking the incoming headers
(if-none-match and if-modified-since) and responding accordingly with
response.statuscode and response headers (last-modified and etag).
This seems to achieve the desired effect.

Another question I have about this is, using the httpcachepolicy
settings, including file dependencies, can I get ASP.NET's cache to
achieve the same effect? Thanks again.

-Grant