OutputCacheLocation Énumération

Définition

Spécifie les valeurs valides pour le contrôle de l'emplacement de la réponse HTTP mise en cache de sortie pour une ressource.

public enum class OutputCacheLocation
public enum OutputCacheLocation
type OutputCacheLocation = 
Public Enum OutputCacheLocation
Héritage
OutputCacheLocation

Champs

Any 0

Le cache de sortie peut se trouver sur le navigateur client (à l'origine de la demande), sur un serveur proxy (ou tout autre serveur) participant à la demande ou bien sur le serveur où la demande a été traitée. Cette valeur correspond à celle de l'énumération Public.

Client 1

Le cache de sortie se trouve sur le navigateur client à l'origine de la demande. Cette valeur correspond à celle de l'énumération Private.

Downstream 2

Le cache de sortie peut être stocké sur n'importe quel appareil offrant des fonctionnalités de mise en cache HTTP 1.1 autre que le serveur d'origine. Cela inclut les serveurs proxy et le client à l'origine de la demande.

None 4

Le cache de sortie est désactivé pour la page demandée. Cette valeur correspond à celle de l'énumération NoCache.

Server 3

Le cache de sortie se trouve sur le serveur Web où la demande a été traitée. Cette valeur correspond à celle de l'énumération Server.

ServerAndClient 5

Le cache de sortie ne peut être stocké que sur le serveur d'origine ou le client demandeur. Les serveurs proxy ne sont pas autorisés à mettre la réponse en cache. Cette valeur correspond à la combinaison des valeurs d'énumération Private et Server.

Exemples

L’exemple de code suivant montre comment la valeur serveur est utilisée pour spécifier que la page doit être mise en cache sur le serveur web où la demande est traitée.

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

Remarques

Les valeurs spécifiées par cette énumération sont utilisées lorsque vous incluez une @ OutputCache directive dans un fichier .aspx. Ces valeurs déterminent l’emplacement du cache pour la sortie de page. Pour plus d’informations, consultez Mise en cache des pages ASP.NET.

S’applique à

Voir aussi