OutputCacheLocation 枚举

定义

指定有效值,用于控制资源的输出缓存 HTTP 响应的位置。

public enum class OutputCacheLocation
public enum OutputCacheLocation
type OutputCacheLocation = 
Public Enum OutputCacheLocation
继承
OutputCacheLocation

字段

Any 0

输出缓存可位于产生请求的浏览器客户端、参与请求的代理服务器(或任何其他服务器)或处理请求的服务器上。 此值对应于 Public 枚举值。

Client 1

输出缓存位于产生请求的浏览器客户端上。 此值对应于 Private 枚举值。

Downstream 2

输出缓存可存储在任何 HTTP 1.1 可缓存设备中,源服务器除外。 这包括代理服务器和发出请求的客户端。

None 4

对于请求的页,禁用输出缓存。 此值对应于 NoCache 枚举值。

Server 3

输出缓存位于处理请求的 Web 服务器上。 此值对应于 Server 枚举值。

ServerAndClient 5

输出缓存只能存储在源服务器或请求客户端中。 代理服务器不能缓存响应。 此值对应于 PrivateServer 枚举值的组合。

示例

下面的代码示例演示如何使用 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 xmlns="http://www.w3.org/1999/xhtml" >
<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>
<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
<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>

注解

在 .aspx 文件中包含 @ OutputCache 指令时,将使用此枚举指定的值。 这些值确定页面输出的缓存位置。 有关详细信息,请参阅 缓存 ASP.NET 页

适用于

另请参阅