Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 缓存设置是否被.NET忽略?_C#_Jquery_Web Services_Caching_Asmx - Fatal编程技术网

C# 缓存设置是否被.NET忽略?

C# 缓存设置是否被.NET忽略?,c#,jquery,web-services,caching,asmx,C#,Jquery,Web Services,Caching,Asmx,我从jQueryAjax调用了一个WebMethod。无论我做什么,我似乎都无法让缓存在返回的JSON数据上正常工作。下面是C#的外观: 无论我做什么,我都无法获取响应的HTTP头以允许缓存: 缓存控制:无缓存 内容长度:918821 内容类型:application/json;字符集=utf-8 日期:2012年12月10日星期一19:40:57 GMT 过期:-1 Pragma:没有缓存 服务器:Microsoft IIS/8.0 X-Powered-By:ASP.NET 最后,通过C#设

我从jQueryAjax调用了一个WebMethod。无论我做什么,我似乎都无法让缓存在返回的JSON数据上正常工作。下面是C#的外观:

无论我做什么,我都无法获取响应的HTTP头以允许缓存:

缓存控制:无缓存
内容长度:918821
内容类型:application/json;字符集=utf-8
日期:2012年12月10日星期一19:40:57 GMT
过期:-1
Pragma:没有缓存
服务器:Microsoft IIS/8.0
X-Powered-By:ASP.NET
最后,通过C#设置这些头似乎对缓存行为没有任何影响:

HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(10));
HttpContext.Current.Response.Cache.SetValidUntilExpires(true);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Private);

这是因为默认情况下动态数据不会缓存

下面是一个自定义HttpHandler的实现,它将允许:

HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(10));
HttpContext.Current.Response.Cache.SetValidUntilExpires(true);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Private);