OutputCacheLocation Enumerazione

Definizione

Specifica i valori validi per il controllo della posizione della risposta HTTP inserita nella cache di output per una risorsa.

public enum class OutputCacheLocation
public enum OutputCacheLocation
type OutputCacheLocation = 
Public Enum OutputCacheLocation
Ereditarietà
OutputCacheLocation

Campi

Any 0

La cache di output può trovarsi nel client browser in cui ha avuto origine la richiesta, in un server proxy (o in un altro server) che partecipa alla richiesta oppure nel server dove la richiesta è stata elaborata. Questo valore corrisponde al valore dell'enumerazione Public.

Client 1

La cache di output si trova nel client browser in cui ha avuto origine la richiesta. Questo valore corrisponde al valore dell'enumerazione Private.

Downstream 2

La cache di output può essere archiviata in qualsiasi dispositivo HTTP 1.1 che supporti la cache, diverso dal server di origine. Sono inclusi i server proxy e il client che ha generato la richiesta.

None 4

La cache di output è disabilitata per la pagina richiesta. Questo valore corrisponde al valore dell'enumerazione NoCache.

Server 3

La cache di output si trova nel server Web dove la richiesta è stata elaborata. Questo valore corrisponde al valore dell'enumerazione Server.

ServerAndClient 5

La cache di output può essere archiviata solo nel server di origine o nel client richiedente. Ai server proxy non è consentito memorizzare nella cache la risposta. Questo valore corrisponde alla combinazione dei valori dell'enumerazione Private e Server.

Esempio

Nell'esempio di codice seguente viene illustrato come viene usato il valore server per specificare che la pagina deve essere memorizzata nella cache nel server Web in cui viene elaborata la richiesta.

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

Commenti

I valori specificati da questa enumerazione vengono usati quando si include una @ OutputCache direttiva in un file aspx. Questi valori determinano il percorso della cache per l'output della pagina. Per altre informazioni, vedere Memorizzazione nella cache di pagine ASP.NET.

Si applica a

Vedi anche