我在我的 asp.net 页面 (asp.net 4.0) 中添加了一个 outputcache 指令:
<%@ OutputCache Duration="3600" Location="Client" VaryByParam="None" %>
但是,这似乎不起作用。当我检查 http header 信息时,我看到了这个:
HTTP/1.1 200 OK =>
Cache-Control => no-cache, no-store
Pragma => no-cache
Content-Type => text/html; charset=utf-8
Expires => -1
Server => Microsoft-IIS/7.0
X-AspNet-Version => 4.0.30319
Set-Cookie => ASP.NET_SessionId=0txhgxrykz5atrc3a42lurn1; path=/; HttpOnly
X-Powered-By => ASP.NET
Date => Tue, 15 Nov 2011 20:47:28 GMT
Connection => close
Content-Length => 17428
以上显示未应用 OutputCache 指令。我什至从代码隐藏中尝试过这个:
this.Response.Cache.SetExpires(DateTime.Now.AddHours(1.0));
TimeSpan ds = new TimeSpan(0, 1, 0, 0);
this.Response.Cache.SetMaxAge(ds);
上面的代码应该与 OutputCache 指令有相同的结果,但是当我检查 http header 信息时,我可以看到它仍然没有被应用。
基本上,这里的目的是确保当用户单击后退按钮并登陆我的页面时,不会从服务器检索该页面。我想避免出现要求用户“重新发送”的浏览器弹出窗口。我希望浏览器只使用缓存中的页面副本。
提前感谢您的帮助。
最佳答案
从你的问题:
I want to avoid getting the browser popup that asks the user to 'resend.' I want the browser to just use the copy of the page it has in it's cache.
如果浏览器要求您重新发送数据,则表示内容是对 POST 请求的响应。
根据 RFC 2616 - Hypertext Transfer Protocol -- HTTP/1.1 :
Some HTTP methods MUST cause a cache to invalidate an entity. This is either the entity referred to by the Request-URI, or by the Location
or Content-Location headers (if present). These methods are:
- PUT
- DELETE
- POST
因此,要使缓存工作,您需要将 POST 转换为 GET。
关于asp.net - OutputCache 指令在 Asp.Net 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8143226/