OutputCacheLocation OutputCacheLocation OutputCacheLocation OutputCacheLocation Enum

定义

指定有效值,用于控制资源的输出缓存 HTTP 响应的位置。Specifies the valid values for controlling the location of the output-cached HTTP response for a resource.

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

字段

Any Any Any Any 0

输出缓存可位于产生请求的浏览器客户端、参与请求的代理服务器(或任何其他服务器)或处理请求的服务器上。The output cache can be located on the browser client (where the request originated), on a proxy server (or any other server) participating in the request, or on the server where the request was processed. 此值对应于 Public 枚举值。This value corresponds to the Public enumeration value.

Client Client Client Client 1

输出缓存位于产生请求的浏览器客户端上。The output cache is located on the browser client where the request originated. 此值对应于 Private 枚举值。This value corresponds to the Private enumeration value.

Downstream Downstream Downstream Downstream 2

输出缓存可存储在任何 HTTP 1.1 可缓存设备中,源服务器除外。The output cache can be stored in any HTTP 1.1 cache-capable devices other than the origin server. 这包括代理服务器和发出请求的客户端。This includes proxy servers and the client that made the request.

None None None None 4

对于请求的页,禁用输出缓存。The output cache is disabled for the requested page. 此值对应于 NoCache 枚举值。This value corresponds to the NoCache enumeration value.

Server Server Server Server 3

输出缓存位于处理请求的 Web 服务器上。The output cache is located on the Web server where the request was processed. 此值对应于 Server 枚举值。This value corresponds to the Server enumeration value.

ServerAndClient ServerAndClient ServerAndClient ServerAndClient 5

输出缓存只能存储在源服务器或请求客户端中。The output cache can be stored only at the origin server or at the requesting client. 代理服务器不能缓存响应。Proxy servers are not allowed to cache the response. 此值对应于 PrivateServer 枚举值的组合。This value corresponds to the combination of the Private and Server enumeration values.

示例

下面的代码示例演示如何服务器值用于指定应在 Web 服务器上缓存的页面处理请求。The following code example demonstrates how the Server value is used to specify that the page should be cached on the Web server where the request is processed.

<%@ 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>

注解

当包括时使用此枚举由指定的值@ OutputCache指令在.aspx 文件中。The values specified by this enumeration are used when you include an @ OutputCache directive in an .aspx file. 这些值确定页面输出缓存位置。These values determine the cache location for page output. 有关详细信息,请参阅缓存 ASP.NET 页面For more information, see Caching ASP.NET Pages.

适用于

另请参阅