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

輸出快取可以位在瀏覽器用戶端 (要求的來源)、參予要求的 Proxy 伺服器 (或任何其他的伺服器) 或要求已處理的所在伺服器上。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. 這包含 Proxy 伺服器和提出要求的用戶端。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 伺服器不能快取回應。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>

備註

當您在 .aspx 檔案中包含@ OutputCache指示詞時, 會使用這個列舉所指定的值。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.

適用於

另請參閱