Clear Cache in ASP. NET (disable page cache)

Source: Internet
Author: User

When you use the dialog mode in asp.net, you will find that each time the page is opened with the same content, the page content is not refreshed, this is the reason for the cache,

The solution is as follows:

First, ASP. NET clears the page cache.

The code is as follows: Copy code

Response. Buffer = true;
Response. ExpiresAbsolute = System. DateTime. Now. AddSeconds (-1 );
Response. Expires = 0;
Response. CacheControl = "no-cache ";
Response. AddHeader ("Pragma", "No-Cache ");

The second method is the HTML method.

The code is as follows: Copy code

<HEAD>
<META HTTP-EQUIV = "Pragma" CONTENT = "no-cache">
<META HTTP-EQUIV = "Cache-Control" CONTENT = "no-cache">
<META HTTP-EQUIV = "Expires" CONTENT = "0">
</HEAD>

The third is to pass a parameter to the page when calling the original page again: href = "*****. ASPX? Random ()"

The last option is to disable caching on the page.

The rational use of cache in web development can effectively improve the performance of the website. However, in some cases, the existence of cache may cause many problems.

For example, the cache may cause repeated data submission and incorrect display of verification code images. In this case, we need to disable the page cache function.

Our common practice is to send a "no-cache" command, but in actual use, we found that this command is valid for IE, but not for Firefox, this is because Firefox does not cache HTTPS pages but will still cache HTTP pages. This is a BUG in Firefox. The solution is simple, that is, replacing no-cache with no-store, send no-store and no-cache commands at the same time

In ASP.net, add the following code to the page that does not require caching:

Response. Cache. SetCacheability (System. Web. HttpCacheability. NoCache );
Response. Cache. SetNoStore ();

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.