ASP.NET Tutorial/Development/OutputCache — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 11:56, 26 мая 2010
OutputCache Duration="30" VaryByParam=true (C#)
<%@ Page Language="C#" %>
<%@ OutputCache Duration="30" VaryByParam="true"%>
<script runat="server">
void Page_Load(Object Sender, EventArgs e) {
lblMessage.Text = "Welcome " + Request.Params["id"] + "! The time is now " + DateTime.Now.ToString("T");
}
</script>
<html><body>
<asp:Label id="lblMessage" runat="server"/>
</body></html>
Set VaryByParam (VB.net)
<%@ Page Language="VB" %>
<%@ OutputCache Duration="60" VaryByParam="none" %>
<script runat="server">
sub Page_Load(Sender as Object, e as EventArgs)
Response.Cache.VaryByParams.Item("first") = true
Response.Cache.VaryByParams.Item("last") = false
lblMessage.Text = "Welcome " & Request.Params("first") & _
"! The time is now " & DateTime.Now.ToString("T")
lblMessage.Text += "<br>" & Response.Cache. _
VaryByParams.Item("first").ToString
lblMessage.Text += "<br>" & Response.Cache. _
VaryByParams.Item("last").ToString
end sub
</script>
<html><body>
<form runat="server">
<asp:Label id="lblMessage" runat="server"/>
</form>
</body></html>
Using the Output Cache (C#)
<%@ Page Language="C#" %>
<%@ OutputCache Duration="30" VaryByParam="none" %>
<script runat="server">
void Page_Load(Object Sender, EventArgs e) {
lblMessage.Text = "Welcome! The time is now " + DateTime.Now.ToString("T");
}
</script>
<html><body>
<asp:Label id="lblMessage" runat="server"/>
</body></html>