Hi,
I have a webservice to download files. With every incoming request, i check for the checksum and timestamp of the file requested to be downloaded, and the file on the server. In case they are same, i dont have to download it again.
The code on server side is:
string checksum; //calculate this using methods in System.Security.Cryptography
string timestamp = File.GetLastAccessTimeUtc(filename).ToString();
string incCheckSum = WebOperationContext.Current.IncomingRequest.Header["If-None-Match"];
string incTimestamp = WebOperationContext.Current.IncomingRequest.Header["If-Modified-Since"];
if(checksum == incCheckSum && timestamp == incTimeStamp)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotModified;
return null;
}
WebOperationContext.Current.OutgoingResponse.Headers["Last-Modified"] = timestamp;
WebOperationContext.Current.OutgoingResponse.Headers["ETag"] = checksum;
return FileStream("Filename",FileMode.Open, FileAccess.Read,FileShare.Read);
On the client side:
HttpWebRequest request = (HttpWebRequest)WebRequest.create("http://somewebsite.com");
request.Header["If-None-Match"] = //get checksum file on the disk
request.Header["If-Modified-Since"] = "Last Modified Time" // I get an exception here:
The exception says,
"The header must be modified using the appropriate property"
Then I do
request.IfModifiedSince = //Last Access UTC time of the file
Now, this change causes problems. Whenever a request comes to server, the last access time always is in a different format and it never matches. So if the last modified time of file is 8/13/2010 5:27:12 PM, on the server side i am getting ["If-Modified-Since"] value as "Fri, 13 Aug 2010 17:27:12 GMT"
How can I correct this?
When I use fiddler and add to "request headers" the following:
If-Modified-Since= last access time
If-None-Match= checksum
this works fine.