OutputCacheLocation 列舉

定義

指定有效值,以控制資源輸出快取 HTTP 回應的位置。

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

欄位

Any 0

輸出快取可以位在瀏覽器用戶端 (要求的來源)、參予要求的 Proxy 伺服器 (或任何其他的伺服器) 或要求已處理的所在伺服器上。 這個值對應於 Public 列舉值。

Client 1

輸出快取位在要求所來自的瀏覽器用戶端。 這個值對應於 Private 列舉值。

Downstream 2

輸出快取可以儲存在任何 HTTP 1.1 快取功能裝置中,而不可以儲存在來源伺服器中。 這包含 Proxy 伺服器和提出要求的用戶端。

None 4

輸出快取會針對要求的頁面停用。 這個值對應於 NoCache 列舉值。

Server 3

輸出快取位在要求已處理的 Web 伺服器上。 這個值對應於 Server 列舉值。

ServerAndClient 5

輸出快取只可以儲存在原始伺服器或提出要求的用戶端。 Proxy 伺服器不能快取回應。 這個值對應於 PrivateServer 列舉值的組合。

範例

下列程式碼範例示範如何使用 Server 值來指定應該在處理要求的網頁伺服器上快取頁面。

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

適用於

另請參閱