Set ASP. NET pages not to be cached (the Client/Server Side cancels the cache)

Source: Internet
Author: User

Copy codeThe Code is as follows: // <summary>
/// Set the page not to be cached
/// </Summary>
Private void SetPageNoCache ()
{
Response. Buffer = true;
Response. ExpiresAbsolute = System. DateTime. Now. AddSeconds (-1 );
Response. Expires = 0;
Response. CacheControl = "no-cache ";
Response. AppendHeader ("Pragma", "No-Cache ");
}

1. Cancel Cache
(2) Client CancellationCopy codeThe Code is as follows:
<Head>
<Meta http-equiv = "Expires" CONTENT = "0">
<Meta http-equiv = "Cache-Control" CONTENT = "no-cache">
<Meta http-equiv = "Pragma" CONTENT = "no-cache">
</Head>

(3) Cancellation of service appliance:
Server:Copy codeThe Code is as follows: Response. Buffer = true;
Response. ExpiresAbsolute = DateTime. Now. AddDays (-1 );
Response. Cache. SetExpires (DateTime. Now. AddDays (-1 ));
Response. Expires = 0;
Response. CacheControl = "no-cache ";
Response. Cache. SetNoStore ();

In Global:Copy codeThe Code is as follows: protected void Application_BeginRequest (Object sender, EventArgs e)
{
HttpContext. Current. Response. Cache. SetNoStore ();
}
<% @ OutPutCache Location = "None" %>

Page Base class:Copy codeThe Code is as follows: public class PageBase: Page
{
Public PageBase (){}
Protected override OnLoad (EventArgs e ){
Response. Cache. SetNoStore ();
Base. OnLoad ();
}
}

The simplest way
To learn about CSDN, add some useless parameters randomly after the URL, for example:
Http: // xxx/xxx.jpg? P = xxx
IE uses URLs to control the cache.

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.