Question

I have an HttpClient being used in an MVC application created as below:

new HttpClient(new WebRequestHandler()
{
    CachePolicy = new RequestCachePolicy(RequestCacheLevel.CacheIfAvailable)
});

I'm sending out a request, and getting a response back as below:

StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  Cache-Control: must-revalidate, max-age=3600
  Date: Thu, 13 Mar 2014 10:26:41 GMT
  Location: <snip!>/api/customers/TEST
  X-AspNet-Version: 4.0.30319
  Content-Length: 246
  Content-Type: application/json; charset=utf-8
  Expires: Thu, 13 Mar 2014 11:26:42 GMT
}

On my local it works fine, but on the staging server when calling the same urls the service is still getting hit; the cache is not being used.

The MVC site using the service is hosted on IIS7, when developing I'm using IIS Express.

Why would there be a difference between running it on my local machine (where caching works) and the staging server (where caching does not work), and how can I fix it so caching works in both cases?

Was it helpful?

Solution

I'm not 100% on this but, I believe that because HttpClient uses the WinInet proxy for caching purposes, it will not work when running as a service. I.e. under IIS. See http://support.microsoft.com/kb/238425 for more details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top