`

ASP.NET中缓存(cache)的控制方法

阅读更多

在开发Web 应用程序的时候,如果不想让客户端缓存 (cache)服务器上的网页,需要在ASP.NET文件的Page_Load中写:Response.Cache.SetCacheability(HttpCacheability.NoCache);

   本人在调式代码的时候无意中发现一些有趣的东西:

      按HTTP 1.0的标准,我们可以在html网页上直接使用 <meta http-equiv="pragma" content="no-cache" /> 

      按HTTP 1.1的标准,我们可以用<meta http-equiv="Cache-Control" content="no-cache" />

    ASP.NET防止客户端缓存服务器上页面的方案
 
   1、在调试的过程中,在aspx页面上面的两个都给用上了,当打印Response 的Http Header的时候居然发现:
         Cache-Control:Private.
   
     本人了解ASP.NET没有办法通过程序来给Response 写入pragma 这个Http Header,这是为什么?

    2、只在aspx页中保留<meta http-equiv="pragma" content="no-cache" />,
          
同时,在程序中写上
Response.Cache.SetCacheability(HttpCacheability.NoCache);

    
打印出Response 的Http Header 结果如下:
               Pragma: No-Cache
               Cache-Control: No-Cache

 

   所有 只有用方案2 才能真正 防止客户端缓存

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics