Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

CacheCow WebAPI & ASP.Net MVC

$
0
0

Hello , 

  •   I have a project ASP.Net Web API . 
  •   I have installed "CacheCow.Server". and I configured it in "WebApiCinfig.cs" .
  •   I open the url in Browser "http://localhost:5343/api/products" . It calls Web Api function. and check the fiddler . the response header has Etag.
  •  I refresh the browser . The Web api function not called and resposnse return "304 Not Modified".

  •  I create ASP.Net MVC Application .
  • I have installed "CacheCow.Client".
  •  In the Action method I write the following code :

       public async Task<ActionResult> Test()

           {

                  var client = new HttpClient(new CachingHandler(){InnerHandler = new HttpClientHandler()});

         client.BaseAddress = new Uri("http://localhost:5343/");

client.DefaultRequestHeaders.Accept.Clear();

client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                 var response = await client.GetAsync("api/Products");

                if (response.IsSuccessStatusCode){return Content("Done");}

else{return Content("An error occurred.");}

}

  • I test it . The '/Test' opened , The action is executed . Then the Web API is called.
  • I Refresh the page "The web API function" is executed again .
  • My expected result : second call the web api not executed because of http caching .

      So why this behavior happened .

   Thanks,

    Hema


Viewing all articles
Browse latest Browse all 4850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>