In my ASP.NET app, I noticed that the results of any web service calls are cached. I don't want any results to be cached, how can I stop the browser from caching the results?
Update:
Here's the proxy code generated by calling the web service URL appending '/js', e.g. /mywebservice.asmx/js
var MyWebService=function() {
MyWebService.initializeBase(this);
this._timeout = 0;
this._userContext = null;
this._succeeded = null;
this._failed = null;
}
MyWebService.prototype={
SomeWebMethod:function(itemID,succeededCallback, failedCallback, userContext) {
return this._invoke(MyWebService.get_path(), 'SomeWebMethod',false,
{itemID:itemID},succeededCallback,failedCallback,userContext); }}
MyWebService.registerClass('MyWebService',Sys.Net.WebServiceProxy);
MyWebService._staticInstance = new MyWebService();
MyWebService.set_path = function(value) { MyWebService._staticInstance._path = value; }
MyWebService.get_path = function() { return MyWebService._staticInstance._path; }
MyWebService.set_timeout = function(value) { MyWebService._staticInstance._timeout = value; }
MyWebService.get_timeout = function() { return MyWebService._staticInstance._timeout; }
MyWebService.set_defaultUserContext = function(value) { MyWebService._staticInstance._userContext = value; }
MyWebService.get_defaultUserContext = function() { return MyWebService._staticInstance._userContext; }
MyWebService.set_defaultSucceededCallback = function(value) { MyWebService._staticInstance._succeeded = value; }
MyWebService.get_defaultSucceededCallback = function() { return MyWebService._staticInstance._succeeded; }
MyWebService.set_defaultFailedCallback = function(value) { MyWebService._staticInstance._failed = value; }
MyWebService.get_defaultFailedCallback = function() { return MyWebService._staticInstance._failed; }
MyWebService.set_path("/MyWebService.asmx");
MyWebService.SomeWebMethod= function(itemID,onSuccess,onFailed,userContext)
{MyWebService._staticInstance.SomeWebMethod(itemID,onSuccess,onFailed,userContext); }
I call the service using:
MyWebService.SomeWebMethod(
itemID,
function(sender, e)
{
// do something
},
function(sender, e)
{
// handle failure
});
I use the suggested technique (append a param to the URL with some random value) with others pages to prevent them from being cached, but I'm surprised that I need to use this technique with a web service call considering that they are POST calls by default in ASP.NET 2.0 and shouldn't be cached in the first place.