更新:2007 年 11 月
指定有效值,用于控制资源的输出缓存 HTTP 响应的位置。
命名空间:
System.Web.UI 程序集:
System.Web(在 System.Web.dll 中)
Public Enumeration OutputCacheLocation
Dim instance As OutputCacheLocation
public enum OutputCacheLocation
public enum class OutputCacheLocation
public enum OutputCacheLocation
public enum OutputCacheLocation
如果在 .aspx 文件中包括 @ OutputCache 指令,则使用该枚举指定的值。这些值确定页输出的缓存位置。有关更多信息,请参见 缓存 ASP.NET 页。
下面的代码示例演示如何使用 Server 值指定应在处理请求的 Web 服务器上缓存页。
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
' The following OutputCache directive uses the OutputCacheLocation.Server
' enumeration value to allow output caching only on the origin server.
<%@ outputcache duration="10" varybyparam="none" Location="Server" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<script language="vb" runat="server">
Protected Sub Page_Load(Src As [Object], E As EventArgs)
Dim ds As New DataSet()
Dim fs As New FileStream(Server.MapPath("schemadata.xml"),FileMode.Open,FileAccess.Read)
Dim reader As New StreamReader(fs)
ds.ReadXml(reader)
fs.Close()
Dim [Source] As New DataView(ds.Tables(0))
MyDataGrid.DataSource = [Source]
MyDataGrid.DataBind()
TimeMsg.Text = DateTime.Now.ToString("G")
End Sub 'Page_Load
</script>
<head runat="server">
<title>Using the OutputCacheLocation Enumeration </title>
</head>
<body>
<h4>Using the OutputCacheLocation Enumeration </h4>
<form id="form1" runat="server">
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="900"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding="3"
CellSpacing="0"
Font-Names="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
EnableViewState="false"
/>
<i>Page last generated on:</i> <asp:label id="TimeMsg" runat="server" />
</form>
</body>
</html>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
// The following OutputCache directive uses the OutputCacheLocation.Server
// enumeration value to allow output caching only on the origin server.
<%@ outputcache duration="10" varybyparam="none" Location="Server" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<script language="C#" runat="server">
protected void Page_Load(Object Src, EventArgs E)
{
DataSet ds = new DataSet();
FileStream fs = new FileStream(Server.MapPath("schemadata.xml"),FileMode.Open,FileAccess.Read);
StreamReader reader = new StreamReader(fs);
ds.ReadXml(reader);
fs.Close();
DataView Source = new DataView(ds.Tables[0]);
// Use the LiteralControl constructor to create a new
// instance of the class.
LiteralControl myLiteral = new LiteralControl();
// Set the LiteralControl.Text property to an HTML
// string and the TableName value of a data source.
myLiteral.Text = "<h6><font face=\"verdana\">Caching an XML Table: " + Source.Table.TableName + " </font></h6>";
MyDataGrid.DataSource = Source;
MyDataGrid.DataBind();
TimeMsg.Text = DateTime.Now.ToString("G");
}
</script>
<head runat="server">
<title>Using the OutputCacheLocation Enumeration </title>
</head>
<body>
<h6>Using the OutputCacheLocation Enumeration </h6>
<form id="form1" runat="server">
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="900"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding="3"
CellSpacing="0"
Font-Names="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
EnableViewState="false"
/>
<i>Page last generated on:</i> <asp:label id="TimeMsg" runat="server" />
</form>
</body>
</html>
// The following OutputCache directive uses the OutputCacheLocation.Server
// enumeration value to allow output caching only on the origin server.
<%@ outputcache duration="10" varybyparam="none" Location="Server" %>
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。
.NET Framework
受以下版本支持:3.5、3.0、2.0、1.1、1.0
参考
其他资源