Editare

Partajați prin


HttpCachePolicy.SetCacheability Method

Definition

Sets the Cache-Control HTTP header. The Cache-Control HTTP header controls how documents are to be cached on the network.

Overloads

SetCacheability(HttpCacheability)

Sets the Cache-Control header to one of the values of HttpCacheability.

SetCacheability(HttpCacheability, String)

Sets the Cache-Control header to one of the values of HttpCacheability and appends an extension to the directive.

SetCacheability(HttpCacheability)

Sets the Cache-Control header to one of the values of HttpCacheability.

public:
 void SetCacheability(System::Web::HttpCacheability cacheability);
public void SetCacheability (System.Web.HttpCacheability cacheability);
member this.SetCacheability : System.Web.HttpCacheability -> unit
Public Sub SetCacheability (cacheability As HttpCacheability)

Parameters

cacheability
HttpCacheability

An HttpCacheability enumeration value.

Exceptions

cacheability is not one of the enumeration values.

Examples

The following code example demonstrates how to set the Cache-Control header to the enumerated value for no-cache.

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetCacheability(HttpCacheability.NoCache)

Remarks

SetCacheability is introduced in the .NET Framework version 3.5. For more information, see Versions and Dependencies.

Applies to

SetCacheability(HttpCacheability, String)

Sets the Cache-Control header to one of the values of HttpCacheability and appends an extension to the directive.

public:
 void SetCacheability(System::Web::HttpCacheability cacheability, System::String ^ field);
public void SetCacheability (System.Web.HttpCacheability cacheability, string field);
member this.SetCacheability : System.Web.HttpCacheability * string -> unit
Public Sub SetCacheability (cacheability As HttpCacheability, field As String)

Parameters

cacheability
HttpCacheability

The HttpCacheability enumeration value to set the header to.

field
String

The cache control extension to add to the header.

Exceptions

field is null.

cacheability is not Private or NoCache.

Examples

The following code example demonstrates how the Cache-Control header is set to the enumeration value private and adds a cache-control extension. The modified directive means that in addition to any non-shared cache, any cache shared only by members of the community named "DEV" may cache the response.

Response.Cache.SetCacheability(HttpCacheability.Private, "Community=DEV");
Response.Cache.SetCacheability(HttpCacheability.Private, "Community=DEV")

Remarks

The field name extension is valid only when used with the private or no-cache directives. For more information, see RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1, available on the World Wide Web Consortium (W3C) Web site.

This method will throw an invalid argument exception if incompatible directives and extensions are combined.

SetCacheability is introduced in the .NET Framework version 3.5. For more information, see Versions and Dependencies.

Applies to