zoukankan      html  css  js  c++  java
  • Asp.Net,代码实现页面输出缓存

    在网上寻找许久,发现很多都是无效的,难道只能用<%@ OutputCache  %>来设置页面缓存?最后终于在 Asp.Net 3.5解密一书中找到我想要的

    在页面的Page_Load事件里添加如下代码:

       protected void Page_Load(object sender, EventArgs e)
            {
                Response.Cache.SetCacheability(HttpCacheability.Public);
                Response.Cache.SetExpires(DateTime.Now.AddSeconds(15));
                //Response.Cache.SetMaxAge(TimeSpan.FromSeconds(15));   //这一句可以不要,它只是决定了客户端什么时候打开页面才向服务器发送请求
                Response.Cache.SetValidUntilExpires(true);//这一句必须要,它的作用是忽略客户端请求信息中的标头Pragma: no-cache,应用服务端页面缓存
                //Response.Cache.SetLastModified(DateTime.Now);//这一句可要可不要,不要的话服务器就不能返回304状态码
                //Response.Cache.SetOmitVaryStar(true);//这一句可以不要
              Response.Write(DateTime.Now.ToString());
            }

  • 相关阅读:
    通讯技术
    (1)sqlserver2017安装
    c# api身份验证和授权
    ()centos7 安装python36
    python 包管理
    ()centos7 安装mysql8.0
    [bzoj1095][ZJOI2007]Hide 捉迷藏 点分树,动态点分治
    bzoj 3544 [ONTAK2010]Creative Accounting 贪心
    BZOJ4300 绝世好题 dp
    bzoj 4295 [PA2015]Hazard 贪心,暴力
  • 原文地址:https://www.cnblogs.com/mxw09/p/1687763.html
Copyright © 2011-2022 走看看