OutputCacheLocation Enumerazione
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Specifica i valori validi per controllare la posizione della risposta HTTP memorizzata nella cache di output per una risorsa.
public enum class OutputCacheLocation
public enum OutputCacheLocation
type OutputCacheLocation =
Public Enum OutputCacheLocation
- Ereditarietà
Campi
| Nome | Valore | Descrizione |
|---|---|---|
| Any | 0 | La cache di output può trovarsi nel client del browser (in cui ha avuto origine la richiesta), in un server proxy (o in qualsiasi altro server) che partecipa alla richiesta o nel server in cui è stata elaborata la richiesta. Questo valore corrisponde al valore di Public enumerazione. |
| Client | 1 | La cache di output si trova nel client del browser in cui ha avuto origine la richiesta. Questo valore corrisponde al valore di Private enumerazione. |
| Downstream | 2 | La cache di output può essere archiviata in qualsiasi dispositivo con supporto per la cache HTTP 1.1 diverso dal server di origine. Sono inclusi i server proxy e il client che ha effettuato la richiesta. |
| Server | 3 | La cache di output si trova nel server Web in cui è stata elaborata la richiesta. Questo valore corrisponde al valore di Server enumerazione. |
| None | 4 | La cache di output è disabilitata per la pagina richiesta. Questo valore corrisponde al valore di NoCache enumerazione. |
| ServerAndClient | 5 | La cache di output può essere archiviata solo nel server di origine o nel client richiedente. I server proxy non sono autorizzati a memorizzare nella cache la risposta. Questo valore corrisponde alla combinazione dei valori di Private e Server di enumerazione. |
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 utilizzati quando si include una @ OutputCache direttiva in un file di .aspx. Questi valori determinano il percorso della cache per l'output della pagina. Per altre informazioni, vedere Caching ASP.NET Pages.