【发布时间】:2012-12-07 18:19:51
【问题描述】:
这是我想不通的事情。
我有大型 JSON 数据集,希望客户端在浏览器中缓存。 我正在使用 jquery AJAX 调用 c# web 方法。
[System.Web.Services.WebMethod]
这是 jQuery:
$.ajax({
url: "/Ajax/ItemAffinity.aspx/FetchAffinityItems?ItemID=" + escape($("#SearchSelectedPageID").val()),
type: "POST",
data: "{}",
cache: true,
contentType: "application/json; charset=utf-8",
dataType: "json",
//contentType: "application/json; charset=utf-8",
success: function (data) {
//do cool stuff
}
});
无论我在 web 方法中在服务器上指定什么,HTTP HEADERS 总是像这样返回:
Cache-Control no-cache
Content-Length 919527
Content-Type application/json; charset=utf-8
Expires -1
我在网络服务中的任何设置都会被立即忽略,如下所示:
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(1));
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
Web 服务不适用于 HTTP GET,对吧? 或者我应该怎么做?
谢谢!
【问题讨论】:
标签: c# web-services jquery http-caching