C# WebClient disable cache
You could try appending some random number to your url as part of a querystring each time you download the file. This ensures that urls are unique each time.
For ex-
Random random = new Random();
string url = originalUrl + "?random=" + random.Next().ToString();
webclient.DownloadFile(url, downloadedfileurl);
From the above I would guess that you have problem somewhere else. Can you log http requests on server side? What do you get when you alter some random seed parameter?
Maybe SERVER caches the file (if the log shows that request is really triggered every minute.
Do you use ISA or SQUID?
What is http response code for your request?
I know that answering with answers might not be popular, but comment doesn't allow me this much text :)
EDIT:
Anyway, use HttpRequest
object instead of WebClient
, and hopefully (if you place your doubts in WebClient
) everything will be solved. If it wasn't solved with HttpRequest
, then the problem really IS somewhere else.
Further refinement:
Go even lower: How do I Create an HTTP Request Manually in .Net?
This is pure sockets, and if the problem still persists, then open a new question and tag it WTF :)
Try NoCacheNoStore
:
Never satisfies a request by using resources from the cache and does not cache resources. If the resource is present in the local cache, it is removed. This policy level indicates to intermediate caches that they should remove the resource. In the HTTP caching protocol, this is achieved using the no-cache cache control directive.
client.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
In some scenarios, network debugging software can cause this issue. To make sure your url is not cached, you can append a random number as last parameter to make url unique. This random parameter in most cases is ignored by servers (which try to read parameters sent as name value pairs).
Example: http://www.someserver.com/?param1=val1&ThisIsRandom=RandomValue
Where ThisIsRandom=RandomValue is the new parameter added.