By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,448 Members | 1,378 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,448 IT Pros & Developers. It's quick & easy.

[REPOST] Dispable Http Caching

P: n/a
Hello All,

Apologies to everyone, I posted this before but received no response. I
feel someone must have come accross this problem before, and I need a
solution desparately.

I have written a C# program which downloads a file from a webserver on a
daily basis. (http://www.myserver.com/myfile.asp)

The problem is that either the proxy/browser's cache is being used
because my C# program runs successfully but downloads the file from
previous run.

Now, if I open my browser and visit that URL, click refresh plenty of
times, I see the latest file. Now if I run my C# program to download
file, the program also downloads the latest file.

So the either the Browsers or the proxy's cache is being used.

I want to always download the latest file. So my C# program should not
use the cache at all.

How do I make sure that no cache is used (either the browser or proxy).
Here is the code snipped from my program.
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create("http://www.myserver.com/downloadfile.asp");
WebProxy proxy = new WebProxy();
proxy.Address = new Uri("http://myproxy:8088");
request.Proxy = proxy;
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
if (response != null)
{
Stream responseStream = response.GetResponseStream();
Encoding encoding = Encoding.GetEncoding("UTF-8");
if (reader != null)
{
char[] buffer = new char[BUFFER_SIZE];
int count = reader.Read(buffer, 0, BUFFER_SIZE);
while(count > 0)
{
......
}
}
}

I saw all the properties of the HttpWebRequest and WebProxy classes but
could find anything which disables caching for me.

Thanks for your help in advace.

regards,
Abhishek.
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Abhishek Srivastava wrote:
Hello All,

Apologies to everyone, I posted this before but received no response.
I feel someone must have come accross this problem before, and I need
a solution desparately.

I have written a C# program which downloads a file from a webserver
on a daily basis. (http://www.myserver.com/myfile.asp)

The problem is that either the proxy/browser's cache is being used
because my C# program runs successfully but downloads the file from
previous run.

Now, if I open my browser and visit that URL, click refresh plenty of
times, I see the latest file. Now if I run my C# program to download
file, the program also downloads the latest file.

So the either the Browsers or the proxy's cache is being used.

I want to always download the latest file. So my C# program should not
use the cache at all.

How do I make sure that no cache is used (either the browser or
proxy). Here is the code snipped from my program.

[...]

Client-side: Don't use the proxy ;-)

or

Client-side: Set an If-Modified-Since request with the previous day's date.
Server-side: Set appropriate caching headers that force your file to expire
after one day.

Cheers,

--
Joerg Jooss
jo*********@gmx.net

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.