<i id='zEu81'><tr id='zEu81'><dt id='zEu81'><q id='zEu81'><span id='zEu81'><b id='zEu81'><form id='zEu81'><ins id='zEu81'></ins><ul id='zEu81'></ul><sub id='zEu81'></sub></form><legend id='zEu81'></legend><bdo id='zEu81'><pre id='zEu81'><center id='zEu81'></center></pre></bdo></b><th id='zEu81'></th></span></q></dt></tr></i><div id='zEu81'><tfoot id='zEu81'></tfoot><dl id='zEu81'><fieldset id='zEu81'></fieldset></dl></div>

          <bdo id='zEu81'></bdo><ul id='zEu81'></ul>
      1. <tfoot id='zEu81'></tfoot>

        <small id='zEu81'></small><noframes id='zEu81'>

        <legend id='zEu81'><style id='zEu81'><dir id='zEu81'><q id='zEu81'></q></dir></style></legend>

        ASP.NET 中的缓存控制标头

        时间:2023-08-26
        <legend id='o0Y0X'><style id='o0Y0X'><dir id='o0Y0X'><q id='o0Y0X'></q></dir></style></legend>

            • <bdo id='o0Y0X'></bdo><ul id='o0Y0X'></ul>

                <tbody id='o0Y0X'></tbody>

              <i id='o0Y0X'><tr id='o0Y0X'><dt id='o0Y0X'><q id='o0Y0X'><span id='o0Y0X'><b id='o0Y0X'><form id='o0Y0X'><ins id='o0Y0X'></ins><ul id='o0Y0X'></ul><sub id='o0Y0X'></sub></form><legend id='o0Y0X'></legend><bdo id='o0Y0X'><pre id='o0Y0X'><center id='o0Y0X'></center></pre></bdo></b><th id='o0Y0X'></th></span></q></dt></tr></i><div id='o0Y0X'><tfoot id='o0Y0X'></tfoot><dl id='o0Y0X'><fieldset id='o0Y0X'></fieldset></dl></div>
              <tfoot id='o0Y0X'></tfoot>

                <small id='o0Y0X'></small><noframes id='o0Y0X'>

                  本文介绍了ASP.NET 中的缓存控制标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  I am trying to set the cache-control headers for a web application (and it appears that I'm able to do it), but I am getting what I think are odd entries in the header responses. My implementation is as follows:

                      protected override void OnLoad(EventArgs e)
                      {
                          // Set Cacheability...
                          DateTime dt = DateTime.Now.AddMinutes(30);
                          Response.Cache.SetExpires(dt);
                          Response.Cache.SetMaxAge(new TimeSpan(dt.ToFileTime()));
                  
                          // Complete OnLoad...
                          base.OnLoad(e);
                      }
                  

                  And this is what the header responses show:

                  -----
                  GET /Pages/Login.aspx HTTP/1.1
                  Host: localhost:1974
                  User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)
                  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
                  Accept-Language: en-us,en;q=0.5
                  Accept-Encoding: gzip,deflate
                  Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
                  Keep-Alive: 300
                  Connection: keep-alive
                  X-lori-time-1: 1244048076221
                  Cache-Control: max-age=0
                  
                  HTTP/1.x 200 OK
                  Server: ASP.NET Development Server/8.0.0.0
                  Date: Wed, 03 Jun 2009 16:54:36 GMT
                  X-AspNet-Version: 2.0.50727
                  Content-Encoding: gzip
                  Cache-Control: private, max-age=31536000
                  Expires: Wed, 03 Jun 2009 17:24:36 GMT
                  Content-Type: text/html; charset=utf-8
                  Content-Length: 6385
                  Connection: Close
                  -----
                  

                  1. Why does the "Cache-Control" property show up twice?
                  2. Do I need both "Cache-Control" and the "Expires" properties?
                  3. Is "Page_Load" the best place to put this code?

                  Thanks!

                  解决方案

                  You might also want to add this line if you are setting the max age that far out :

                  // Summary:
                  // Sets Cache-Control: public to specify that the response is cacheable
                  // by clients and shared (proxy) caches.    
                  Response.Cache.SetCacheability(HttpCacheability.Public);
                  

                  I do a lot of response header manip with documents and images from a file handler that processes requests for files the are saved in the DB.

                  Depending on your goal you can really force the browsers the cache almost all of you page for days locally ( if thats what u want/need ).

                  edit:

                  I also think you might be setting the max age wrong...

                  Response.Cache.SetMaxAge(new TimeSpan(dt.Ticks - DateTime.Now.Ticks ));
                  

                  this line set is to 30 min cache time on the local browser [max-age=1800]

                  As for the 2x Cache Control lines... you might want to check to see if IIS has been set to add the header automatically.

                  这篇关于ASP.NET 中的缓存控制标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PdfPTable 作为 iTextSharp 中的标题 下一篇:如何防止 WebClient 类自动跟随标头中的位置?

                  相关文章

                  最新文章

                  • <bdo id='AZI3j'></bdo><ul id='AZI3j'></ul>

                    <tfoot id='AZI3j'></tfoot>

                    <small id='AZI3j'></small><noframes id='AZI3j'>

                      <i id='AZI3j'><tr id='AZI3j'><dt id='AZI3j'><q id='AZI3j'><span id='AZI3j'><b id='AZI3j'><form id='AZI3j'><ins id='AZI3j'></ins><ul id='AZI3j'></ul><sub id='AZI3j'></sub></form><legend id='AZI3j'></legend><bdo id='AZI3j'><pre id='AZI3j'><center id='AZI3j'></center></pre></bdo></b><th id='AZI3j'></th></span></q></dt></tr></i><div id='AZI3j'><tfoot id='AZI3j'></tfoot><dl id='AZI3j'><fieldset id='AZI3j'></fieldset></dl></div>
                    1. <legend id='AZI3j'><style id='AZI3j'><dir id='AZI3j'><q id='AZI3j'></q></dir></style></legend>