Cache Control Method in ASP. NET

Source: Internet
Author: User

If you do not want the client to cache web pages on your server, you can control the following in ASP. NET:

Write in page_load:

Response. cache. setcacheability(Httpcacheability. nocache );

I found some interesting things during the test:

According to the HTTP 1.0 standard, you can directly use <meta http-equiv = "Pragma" content = "no-Cache"/>

According to the HTTP 1.1 Standard, you can use: <meta http-equiv = "cache-control" content = "no-Cache"/>

For the sake of insurance, both of them are used.

However, when I try to add these two meta tags to the ASPX page, the returned HTTP header shows cache-control: Private.

Moreover, ASP. NET cannot write the HTTP header Pragma to response through a program.

The final solution is to add <meta http-equiv = "Pragma" content = "no-Cache"/> to the ASPX page, and then writeResponse. cache. setcacheability(Httpcacheability. nocache );

In this way, the returned response contains the two headers that I expected:

Pragma: No-Cache

Cache-control: No-Cache

Strange. If anyone knows what I did wrong, please kindly advise.

 

========================================================== ========================

Here are some related articles:

How to: Set the cacheability of an ASP. NET page declaratively

How to: Set the cacheability of an ASP. NET page programmatically

There is also fiddler this tool is good, used to debug the use of HTTP protocol program is very good: http://www.fiddlertool.com/fiddler/

 

In addition: Recently, I have been familiar with HTTP protocols and various RFC types. I think it is really difficult to develop standards. It is very helpful. Finally, I have to be picked up. There is a saying in the IT industry: A third-stream enterprise is a product, a second-stream enterprise is a technology, and a first-class enterprise is a standard. It makes sense.

Are you interested in comparing rest and soap? We can exchange ideas.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.