Disable page cache program code in asp.net

Source: Internet
Author: User
Tags datetime

Method 1: Use the Response. Redirect Method on the server or the window. location. replace method on the front-end for navigation.

Method 2: disable ASP. NET page caching.

I recommend method 2 when necessary. Because the browser settings cannot be controlled during development. If you set Internet Explorer to never check and update the cache, it is difficult to avoid this problem. Therefore, use method 2 to make the temporary folder of Internet Explorer non-existent page files.

In addition, whether to disable the page cache depends on the actual situation. At first I thought that the page cache was only cached on the server, and then I read a blog

The significance of cache is large. In many cases, the pressure on the server can be greatly reduced. However, in the development process, we need to focus more on the needs and do not blindly set any attributes.


Prohibit directly in the browser

The code is as follows: Copy code

<Html>
<Head>
<Meta http-equiv = "Expires" CONTENT = "0">
<Meta http-equiv = "Cache-Control" CONTENT = "no-cache">
<Meta http-equiv = "Pragma" CONTENT = "no-cache">
</Head>


Disable page caching in asp.net

Server

The code is as follows: Copy code

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 ();

Global configuration

The code is as follows: Copy code

Protected void Application_BeginRequest (Object sender, EventArgs e)
{
HttpContext. Current. Response. Cache. SetNoStore ();
}

Aspx page

The code is as follows: Copy code

<% @ OutPutCache Location = "None" %>

How to disable cache in C!

The code is as follows: Copy code

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

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.