当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.net Substitution 页面缓存而部分不缓存的实现方法

ASP.net Substitution 页面缓存而部分不缓存的实现方法

2017年12月12日  | 移动技术网IT编程  | 我要评论

巾帼枭雄之义海云天,万客团,一品堂说文解字

文件1:deafault.aspx
复制代码 代码如下:

<%@ page language="c#" autoeventwireup="true" codefile="default.aspx.cs" inherits="_default" %>
<%@ outputcache duration="10" varybyparam="none" %>

<!--设置缓存时间为10秒-->

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">

<html>
<head id="head1" runat="server">
<title>substitution控件实例</title>
</head>
<body>
<form id="form1" runat="server">

<h1>substitution控件实例演示</h1>
您好<b>
<asp:substitution id="m1" methodname="getuser" runat="server">
</asp:substitution></b><br>
当前时间[非缓存]:

<b><asp:substitution id="m2" runat="server" methodname="gettime" /></b>
<br />
缓存: <%=datetime.now.tolongtimestring() %>
<asp:button id="button1" runat="server" text="刷新" />
</form>
</body>
</html>

文件2:deafault.aspx.cs
复制代码 代码如下:

using system;
using system.data;
using system.configuration;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.web.ui.htmlcontrols;

public partial class _default : system.web.ui.page
{

//下面定义了两个表态方法,可以使用substitution控件调用,以实现这两个方法每次刷新时都要调用


public static string getuser(httpcontext context)
{
return context.user.identity.name;
}
public static string gettime(httpcontext context)
{
return datetime.now.tostring();
}
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网