Export (0) Print
Expand All
Expand Minimize

OutputCacheLocation Enumeration

Specifies the valid values for controlling the location of the output-cached HTTP response for a resource.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

public enum OutputCacheLocation

Member nameDescription
AnyThe 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. This value corresponds to the HttpCacheability.Public enumeration value.
ClientThe output cache is located on the browser client where the request originated. This value corresponds to the HttpCacheability.Private enumeration value.
DownstreamThe output cache can be stored in any HTTP 1.1 cache-capable devices other than the origin server. This includes proxy servers and the client that made the request.
NoneThe output cache is disabled for the requested page. This value corresponds to the HttpCacheability.NoCache enumeration value.
ServerThe output cache is located on the Web server where the request was processed. This value corresponds to the HttpCacheability.Server enumeration value.
ServerAndClientThe output cache can be stored only at the origin server or at the requesting client. Proxy servers are not allowed to cache the response. This value corresponds to the combination of the HttpCacheability.Private and HttpCacheability.Server enumeration values.

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. For more information, see Caching ASP.NET Pages.

TopicLocation
How to: Cache Versions of a Page Using HTTP HeadersBuilding ASP .NET Web Applications
How to: Set the Cacheability of an ASP.NET Page DeclarativelyBuilding ASP .NET Web Applications
How to: Set a Page's Cacheability ProgrammaticallyBuilding ASP .NET Web Applications
How to: Cache Page Output with File DependenciesBuilding ASP .NET Web Applications
How to: Cache Versions of a Page Using Requesting BrowserBuilding ASP .NET Web Applications
How to: Set Expiration Values for ASP.NET Page CachingBuilding ASP .NET Web Applications
How to: Cache Page Output with Cache Key DependenciesBuilding ASP .NET Web Applications
How to: Retrieve Values of Cached ItemsBuilding ASP .NET Web Applications
How to: Cache Versions of a Page Using HTTP HeadersBuilding ASP .NET Web Applications
How to: Set the Cacheability of an ASP.NET Page DeclarativelyBuilding ASP .NET Web Applications
How to: Set a Page's Cacheability ProgrammaticallyBuilding ASP .NET Web Applications
How to: Cache Page Output with File DependenciesBuilding ASP .NET Web Applications
How to: Cache Versions of a Page Using Requesting BrowserBuilding ASP .NET Web Applications
How to: Set Expiration Values for ASP.NET Page CachingBuilding ASP .NET Web Applications
How to: Cache Page Output with Cache Key DependenciesBuilding ASP .NET Web Applications
How to: Retrieve Values of Cached ItemsBuilding ASP .NET Web Applications

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>

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft