views:

204

answers:

2

My Silverlight4 app is hosted in ASP.NET MVC 2 web application. I do web request through HttpWebRequest class but it gives back a result previously cached. How to disable this caching behavior? There are some links which talks about HttpWebRequest in .NET but Silverlight HttpWebrequest is different. Someone suggested to add unique dummy query string on every web request, but I'd prefer more elegant solution. I also tried the following, but it didn't work:

_myHttpWebRequest.BeginGetRequestStream(new AsyncCallback(BeginRequest), new Guid());

In fact, by setting browser history settings it is possible to disable caching. See the following link: http://stackoverflow.com/questions/3027145/asp-net-mvc-with-sql-server-backend-returns-old-data-when-query-is-executed But asking a user to change browser settings is not an option for me.

+1  A: 

The correct way to manage the caching is to adjust the server end so that correct values for HTTP headers that affect caching are sent.

For example in ASP.NET you might use the CacheControl property on the Response object

 Response.CacheControl = HttpCacheability.NoCache;
AnthonyWJones
For ASP.NET MVC specific answer see:http://stackoverflow.com/questions/1160105/asp-net-mvc-disable-browser-cache
synergetic
A: 

Ok, I found more correct answer in the following link:

http://stackoverflow.com/questions/1160105/asp-net-mvc-disable-browser-cache

synergetic