在我的ASP.NET应用程序中,我注意到任何Web服务调用的结果被缓存.我不希望任何结果被缓存,我如何阻止浏览器缓存结果?
更新:
以下是通过调用附加了’/ js’的Web服务URL生成的代理代码,例如/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},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,userContext); }
我打电话给服务使用:
MyWebService.SomeWebMethod( itemID,function(sender,e) { // do something },e) { // handle failure });
我使用建议的技术(附带一些随机值的URL参数)与其他页面,以防止它们被缓存,但我很惊讶,我需要使用这种技术与Web服务调用,考虑到他们是POST调用默认情况下,在ASP.NET 2.0中,不应该首先缓存.