.net页面缓存实验笔记
2012-01-03 17:25
253 查看
在项目中新建一个website,新建一个PageCache.aspx页面,在页面代码的第二行填写:
<%@ OutputCache Duration="3" VaryByParam="none" %> //不根据任何URL的参数进行缓存
或
<%@ OutputCache Duration="3" VaryByParam="id" %> //根据URL的参数id进行缓存
PageCache.aspx:
PageCache.aspx.cs:
Web.config:(缓存设置代码见
在IE中运行PageCache.aspx,点击页面上的"ShowTime”按钮,每十秒钟更新一次时间值。
点击"VaryByParam=id"按钮, 每10秒更新一次URL中ID参数=下拉菜单中选中值的页面的时间值
<%@ OutputCache Duration="3" VaryByParam="none" %> //不根据任何URL的参数进行缓存
或
<%@ OutputCache Duration="3" VaryByParam="id" %> //根据URL的参数id进行缓存
PageCache.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PageCache.aspx.cs" Inherits="PageCache" %> <%@ OutputCache CacheProfile="myPageCache" 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> <asp:Button ID="btnShowTime" runat="server" onclick="btnShowTime_Click" Text="ShowTime" /> <asp:TextBox ID="txtShowTime" runat="server"></asp:TextBox> <br /> <asp:Label ID="lbShowTime" runat="server"></asp:Label> <br /> <br /> <br /> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="VaryByParam=id" /> <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> </asp:DropDownList> </div> </form> </body> </html>
PageCache.aspx.cs:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class PageCache : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ShowTime(); } } protected void btnShowTime_Click(object sender, EventArgs e) { txtShowTime.Text = System.DateTime.Now.ToString(); } protected void ShowTime() { lbShowTime.Text = System.DateTime.Now.ToString(); } protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("Pagecache.aspx?id=" + DropDownList1.SelectedValue); } }
Web.config:(缓存设置代码见
<caching>段落)
<?xml version="1.0"?> <!-- For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <connectionStrings> <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" /> </connectionStrings> <system.web> <compilation debug="false" targetFramework="4.0" /> <authentication mode="Forms"> <forms loginUrl="~/Account/Login.aspx" timeout="2880" /> </authentication> <membership> <providers> <clear/> <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /> </providers> </membership> <profile> <providers> <clear/> <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/> </providers> </profile> <roleManager enabled="false"> <providers> <clear/> <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" /> <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" /> </providers> </roleManager> <caching> <outputCache enableOutputCache="true"> </outputCache> <outputCacheSettings> <outputCacheProfiles> <add name="myPageCache" duration="10" enabled="true"/> </outputCacheProfiles> </outputCacheSettings> </caching> </system.web> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </configuration>
在IE中运行PageCache.aspx,点击页面上的"ShowTime”按钮,每十秒钟更新一次时间值。
点击"VaryByParam=id"按钮, 每10秒更新一次URL中ID参数=下拉菜单中选中值的页面的时间值
相关文章推荐
- .net页面缓存
- .NET缓存优化技术学习笔记 V0.1
- 关于.net页面缓存
- .NET的三种缓存(页面缓存,控件缓存,自定义缓存)
- .net页面缓存
- .net 页面输出缓存设置
- .net页面缓存
- OSCache 学习笔记(2)__缓存整个页面 & 缓存局部页面
- 一起谈.NET技术,页面片段缓存(二)
- .NET 网站优化---页面缓存收藏
- iOS原生App与H5页面交互 离线缓存 笔记
- MonoRail学习笔记八:页面缓存的使用
- 一起谈.NET技术,页面片段缓存(一)
- .net 防止页面刷新重复提交(表单提交后保留上一次数据缓存,刷新提交)
- MonoRail学习笔记八:页面缓存的使用
- PHP页面静态化学习笔记之三:使用PHP缓存机制完成静态化
- .NET的三种缓存(页面缓存,控件缓存,自定义缓存)
- .net页面缓存相关
- .NET禁用页面缓存
- ASP.NET 3.5核心编程学习笔记(40):页面缓存