How to screen scrape with no cache.

S

soul_chicken

I'm working on a simple image upload project using the asp:FileUpload
control. I read the file in and stick it into a clients content
management system. The problem is that once I redirect back to a view
page, the cached copy of the image from the content management system
is being returned. Hit "F5" and everything comes back as intended. I
can't make changes to the content management system but I would like to
eliminate the extra keystroke.

My thought was to create a simple webrequest object using the
System.NET.WebClient opbject and request the resource and at the end of
the upload. Basically just a screen scrape of that image url, and
programatically set the Cache-Control header to "no-cache". When I do
this however, the image returned is still the cached copy. Is there
any way to programatically simulate the action that is performed by the
"F5" keystroke?

Thanks,
S

p.s. - here's the code I'm using to do the web request...

Dim req As New System.Net.WebClient()
req.Headers = New System.Net.WebHeaderCollection()

req.Headers.Add(System.Net.HttpRequestHeader.CacheControl, "no-cache")
Dim aRequestedHTML() As Byte
aRequestedHTML = req.DownloadData(ImageUrl)
req.Dispose()
aRequestedHTML = Nothing
 
S

soul_chicken

There are several places that request these resources and I won't be
able to control the behavior of all of them, which I why I went down
the behind the scenes web request route.

I got the solution shortly after I posted...

Dim req As New System.Net.WebClient()
req.Headers = New System.Net.WebHeaderCollection()
req.Headers.Add(System.Net.HttpRequestHeader.CacheControl, "no-cache")
req.Headers.Add(System.Net.HttpRequestHeader.Pragma, "no-cache")

Dim aRequestedHTML() As Byte
req.CachePolicy = New
System.Net.Cache.HttpRequestCachePolicy(Net.Cache.HttpRequestCacheLevel.Reload)
aRequestedHTML = req.DownloadData(ImageUrl)
req.Dispose()
aRequestedHTML = Nothing

S
 

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

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top