Skip Navigation Links
技术文档
·网站建设
·软件使用
·图形设计
·程序开发
·网络应用
·电脑技巧
 
公司介绍
·公司简介
·索仕SRCOS网络应用平台
·索仕网站管理系统
·影视广告制作
·联系我们
 
 

页面级缓存简单使用教程

6/30/2008 12:05:50 PM

Duration属性是用来设置缓存的期限,单位为秒。缓存时间最长为5分钟。

页面级缓存简单使用教程<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Test_Default" %>
页面级缓存简单使用教程
<%@ OutputCache Duration="10" VaryByParam="none" %>
页面级缓存简单使用教程
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
页面级缓存简单使用教程
页面级缓存简单使用教程
<html xmlns="http://www.w3.org/1999/xhtml">
页面级缓存简单使用教程
<head runat="server">
页面级缓存简单使用教程    
<title>无标题页</title>
页面级缓存简单使用教程
</head>
页面级缓存简单使用教程
<body>
页面级缓存简单使用教程    
<form id="form1" runat="server">
页面级缓存简单使用教程    
<div>
页面级缓存简单使用教程    Duration属性是用来设置缓存的期限,单位为秒。缓存时间最长为5分钟。
页面级缓存简单使用教程    
<asp:Label ID="LabelTime" runat="server" Text="Label"></asp:Label>
页面级缓存简单使用教程    
</div>
页面级缓存简单使用教程    
</form>
页面级缓存简单使用教程
</body>
页面级缓存简单使用教程
</html>

 

页面级缓存简单使用教程using System;
页面级缓存简单使用教程
using System.Collections;
页面级缓存简单使用教程
using System.Configuration;
页面级缓存简单使用教程
using System.Data;
页面级缓存简单使用教程
using System.Web;
页面级缓存简单使用教程
using System.Web.Security;
页面级缓存简单使用教程
using System.Web.UI;
页面级缓存简单使用教程
using System.Web.UI.HtmlControls;
页面级缓存简单使用教程
using System.Web.UI.WebControls;
页面级缓存简单使用教程
using System.Web.UI.WebControls.WebParts;
页面级缓存简单使用教程
页面级缓存简单使用教程
public partial class Test_Default : System.Web.UI.Page
{
页面级缓存简单使用教程    
protected void Page_Load(object sender, EventArgs e)
    
{
页面级缓存简单使用教程        
this.LabelTime.Text = DateTime.Now.ToString();
页面级缓存简单使用教程    }

页面级缓存简单使用教程}

页面级缓存简单使用教程


VaryByParam属性是用来指定参数。如果将该属性设置为none,即表示该页面不会根据参数的不同来改变缓存。只要给该属性一个传入的参数,那么,根据参数的不同,就可以创建不同的缓存。
 

页面级缓存简单使用教程<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Test_Default2" %>
页面级缓存简单使用教程
<%@ OutputCache Duration="10" VaryByParam="id" %>
页面级缓存简单使用教程
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
页面级缓存简单使用教程
页面级缓存简单使用教程
<html xmlns="http://www.w3.org/1999/xhtml">
页面级缓存简单使用教程
<head runat="server">
页面级缓存简单使用教程    
<title>无标题页</title>
页面级缓存简单使用教程
</head>
页面级缓存简单使用教程
<body>
页面级缓存简单使用教程    
<form id="form1" runat="server">
页面级缓存简单使用教程    
<div>
页面级缓存简单使用教程    
<h4>VaryByParam属性是用来指定参数。如果将该属性设置为none,即表示该页面不会根据参数的不同来改变缓存。只要给该属性一个传入的参数,那么,根据参数的不同,就可以创建不同的缓存。</h4>
页面级缓存简单使用教程    
<ul>
页面级缓存简单使用教程        
<li><a href="Default2.aspx">没有参数</a></li>
页面级缓存简单使用教程        
<li><a href="Default2.aspx?id=1">参数ID=1</a></li>
页面级缓存简单使用教程        
<li><a href="Default2.aspx?id=2">参数ID=2</a></li>
页面级缓存简单使用教程    
</ul>
页面级缓存简单使用教程        
<asp:Label ID="LabelTime" runat="server" Text="Label"></asp:Label>
页面级缓存简单使用教程    
</div>
页面级缓存简单使用教程    
</form>
页面级缓存简单使用教程
</body>
页面级缓存简单使用教程
</html>
页面级缓存简单使用教程

 

页面级缓存简单使用教程using System;
页面级缓存简单使用教程
using System.Collections;
页面级缓存简单使用教程
using System.Configuration;
页面级缓存简单使用教程
using System.Data;
页面级缓存简单使用教程
using System.Web;
页面级缓存简单使用教程
using System.Web.Security;
页面级缓存简单使用教程
using System.Web.UI;
页面级缓存简单使用教程
using System.Web.UI.HtmlControls;
页面级缓存简单使用教程
using System.Web.UI.WebControls;
页面级缓存简单使用教程
using System.Web.UI.WebControls.WebParts;
页面级缓存简单使用教程
页面级缓存简单使用教程
public partial class Test_Default2 : System.Web.UI.Page
{
页面级缓存简单使用教程    
protected void Page_Load(object sender, EventArgs e)
    
{
页面级缓存简单使用教程        
string ID = Request.Params["id"];
页面级缓存简单使用教程        
if (ID == null)
        
{
页面级缓存简单使用教程            
this.LabelTime.Text = "默认的缓存";
页面级缓存简单使用教程        }

页面级缓存简单使用教程        
else
        
{
页面级缓存简单使用教程            
if (ID == "1")
            
{
页面级缓存简单使用教程                
this.LabelTime.Text = "存储ID=1";
页面级缓存简单使用教程            }

页面级缓存简单使用教程            
if (ID == "2")
            
{
页面级缓存简单使用教程                
this.LabelTime.Text = "存储ID=2";
页面级缓存简单使用教程            }

页面级缓存简单使用教程        }

页面级缓存简单使用教程        
this.LabelTime.Text += "<br />";
页面级缓存简单使用教程        
this.LabelTime.Text += DateTime.Now.ToString(); ;
页面级缓存简单使用教程    }

页面级缓存简单使用教程}

页面级缓存简单使用教程


使用页面分段缓存,在特殊情况下,只需要对页面的一部分进行缓存。如对于每位用户的登录欢迎信息可能会不同,这部分内容就不能进行缓存,而公共浏览的信息部分就可能需要缓存。这就需要用到分段缓存的技术了。其实说白了,这也就是单独的用户控件的应用。即只对用户控件部分缓存,而主页不启用缓存。

 页面级缓存简单使用教程<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Test_Default3" %>
页面级缓存简单使用教程
页面级缓存简单使用教程
<%@ Register src="WebUserControl.ascx" tagname="WebUserControl" tagprefix="uc1" %>
页面级缓存简单使用教程
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
页面级缓存简单使用教程
页面级缓存简单使用教程
<html xmlns="http://www.w3.org/1999/xhtml">
页面级缓存简单使用教程
<head runat="server">
页面级缓存简单使用教程    
<title>无标题页</title>
页面级缓存简单使用教程
</head>
页面级缓存简单使用教程
<body>
页面级缓存简单使用教程    
<form id="form1" runat="server">
页面级缓存简单使用教程    
<div>
页面级缓存简单使用教程    
<h4>使用页面分段缓存,在特殊情况下,只需要对页面的一部分进行缓存。如对于每位用户的登录欢迎信息可能会不同,这部分内容就不能进行缓存,而公共浏览的信息部分就可能需要缓存。这就需要用到分段缓存的技术了。其实说白了,这也就是单独的用户控件的应用。即只对用户控件部分缓存,而主页不启用缓存。</h4>
页面级缓存简单使用教程    
页面级缓存简单使用教程    
<asp:Label ID="LabelDefaultTime" runat="server" Text="Label"></asp:Label>
页面级缓存简单使用教程    
<br />
页面级缓存简单使用教程    
<uc1:WebUserControl ID="WebUserControl1" runat="server" />
页面级缓存简单使用教程    
</div>
页面级缓存简单使用教程    
</form>
页面级缓存简单使用教程
</body>
页面级缓存简单使用教程
</html>
页面级缓存简单使用教程

 

页面级缓存简单使用教程using System;
页面级缓存简单使用教程
using System.Collections;
页面级缓存简单使用教程
using System.Configuration;
页面级缓存简单使用教程
using System.Data;
页面级缓存简单使用教程
using System.Web;
页面级缓存简单使用教程
using System.Web.Security;
页面级缓存简单使用教程
using System.Web.UI;
页面级缓存简单使用教程
using System.Web.UI.HtmlControls;
页面级缓存简单使用教程
using System.Web.UI.WebControls;
页面级缓存简单使用教程
using System.Web.UI.WebControls.WebParts;
页面级缓存简单使用教程
页面级缓存简单使用教程
public partial class Test_Default3 : System.Web.UI.Page
{
页面级缓存简单使用教程    
protected void Page_Load(object sender, EventArgs e)
    
{
页面级缓存简单使用教程        
this.LabelDefaultTime.Text = "页面加载时间:" + DateTime.Now.ToString();
页面级缓存简单使用教程    }

页面级缓存简单使用教程}

页面级缓存简单使用教程

 

页面级缓存简单使用教程<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="Test_WebUserControl" %>
页面级缓存简单使用教程
<%@ OutputCache Duration="10" VaryByParam="none" %>
页面级缓存简单使用教程
<asp:Label ID="LabelContentTime" runat="server" Text="Label"></asp:Label>

 

页面级缓存简单使用教程using System;
页面级缓存简单使用教程
using System.Collections;
页面级缓存简单使用教程
using System.Configuration;
页面级缓存简单使用教程
using System.Data;
页面级缓存简单使用教程
using System.Web;
页面级缓存简单使用教程
using System.Web.Security;
页面级缓存简单使用教程
using System.Web.UI;
页面级缓存简单使用教程
using System.Web.UI.HtmlControls;
页面级缓存简单使用教程
using System.Web.UI.WebControls;
页面级缓存简单使用教程
using System.Web.UI.WebControls.WebParts;
页面级缓存简单使用教程
页面级缓存简单使用教程
public partial class Test_WebUserControl : System.Web.UI.UserControl
{
页面级缓存简单使用教程    
protected void Page_Load(object sender, EventArgs e)
    
{
页面级缓存简单使用教程        
this.LabelContentTime.Text = "缓存加载时间:" + DateTime.Now.ToString();
页面级缓存简单使用教程    }

页面级缓存简单使用教程}

页面级缓存简单使用教程

.Net2.0提供了名为Substitution的新控件,该控件可使开发人员在缓存的web页面中插入动态内容。例如,开发人员可以显示终端用户的名称,该名称在一个缓存的,包含一些文字或者图片的web页面中动态生成。Substitution控件包含MethodName属性,调用该属性设置的方法可以返回动态内容。
 

页面级缓存简单使用教程<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Test_Default4" %>
页面级缓存简单使用教程
<%@ OutputCache Duration="10" VaryByParam="none" %>
页面级缓存简单使用教程
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
页面级缓存简单使用教程
页面级缓存简单使用教程
<html xmlns="http://www.w3.org/1999/xhtml">
页面级缓存简单使用教程
<head runat="server">
页面级缓存简单使用教程    
<title>无标题页</title>
页面级缓存简单使用教程
</head>
页面级缓存简单使用教程
<body>
页面级缓存简单使用教程    
<form id="form1" runat="server">
页面级缓存简单使用教程    
<div>
页面级缓存简单使用教程    
<h4>.Net2.0提供了名为Substitution的新控件,该控件可使开发人员在缓存的web页面中插入动态内容。例如,开发人员可以显示终端用户的名称,该名称在一个缓存的,包含一些文字或者图片的web页面中动态生成。Substitution控件包含MethodName属性,调用该属性设置的方法可以返回动态内容。</h4>
页面级缓存简单使用教程        
<asp:Substitution ID="SubstitutionCache" runat="server" MethodName="GetDateTime" />
页面级缓存简单使用教程        
<br />
页面级缓存简单使用教程        
<asp:Label ID="LabelTime" runat="server" Text="Label"></asp:Label>
页面级缓存简单使用教程    
</div>
页面级缓存简单使用教程    
</form>
页面级缓存简单使用教程
</body>
页面级缓存简单使用教程
</html>

 

页面级缓存简单使用教程using System;
页面级缓存简单使用教程
using System.Collections;
页面级缓存简单使用教程
using System.Configuration;
页面级缓存简单使用教程
using System.Data;
页面级缓存简单使用教程
using System.Web;
页面级缓存简单使用教程
using System.Web.Security;
页面级缓存简单使用教程
using System.Web.UI;
页面级缓存简单使用教程
using System.Web.UI.HtmlControls;
页面级缓存简单使用教程
using System.Web.UI.WebControls;
页面级缓存简单使用教程
using System.Web.UI.WebControls.WebParts;
页面级缓存简单使用教程
页面级缓存简单使用教程
public partial class Test_Default4 : System.Web.UI.Page
{
页面级缓存简单使用教程    
protected void Page_Load(object sender, EventArgs e)
    
{
页面级缓存简单使用教程        
this.LabelTime.Text = "页面加载时间:" + DateTime.Now.ToString();
页面级缓存简单使用教程    }

页面级缓存简单使用教程
页面级缓存简单使用教程    
protected static string GetDateTime(HttpContext context)
    
{
页面级缓存简单使用教程        context.Response.Write(
"22");
页面级缓存简单使用教程    }

页面级缓存简单使用教程}

页面级缓存简单使用教程
作者:菜菜灰 来源:博客园
 
 
 
昆明索仕科技开发有限公司 版权所有 Copyright© 2002-2010 Kunming Source Technology Exploitive Co.,LTD. All Rights Reserved.
电话:0871-5627877 业务QQ:163871 联系我们
本站基于:索仕网站信息管理系统建设 版本 2.0.4325