HttpCachePolicy.SetCacheability 方法

定義

設定 Cache-Control HTTP 標頭。Sets the Cache-Control HTTP header. Cache-Control HTTP 標頭控制文件如何在網路上進行快取。The Cache-Control HTTP header controls how documents are to be cached on the network.

多載

SetCacheability(HttpCacheability)

Cache-Control 標頭設定為其中一個 HttpCacheability 值。Sets the Cache-Control header to one of the values of HttpCacheability.

SetCacheability(HttpCacheability, String)

Cache-Control 標頭設定為其中一個 HttpCacheability 值,並且附加擴充功能到指示詞。Sets the Cache-Control header to one of the values of HttpCacheability and appends an extension to the directive.

SetCacheability(HttpCacheability)

Cache-Control 標頭設定為其中一個 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)

參數

cacheability
HttpCacheability

HttpCacheability 列舉值。An HttpCacheability enumeration value.

例外狀況

cacheability 不是其中一個列舉值。cacheability is not one of the enumeration values.

範例

下列程式碼範例示範如何將 Cache-Control 標頭設定為的列舉值 no-cacheThe 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)
 

備註

SetCacheability 在 .NET Framework 版本3.5 中引進。SetCacheability is introduced in the .NET Framework version 3.5. 如需詳細資訊,請參閱版本和相依性For more information, see Versions and Dependencies.

適用於

SetCacheability(HttpCacheability, String)

Cache-Control 標頭設定為其中一個 HttpCacheability 值,並且附加擴充功能到指示詞。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)

參數

cacheability
HttpCacheability

要設定標頭的目標 HttpCacheability 列舉值。The HttpCacheability enumeration value to set the header to.

field
String

加入標頭的快取控制項擴充功能。The cache control extension to add to the header.

例外狀況

fieldnullfield is null.

cacheability 不是 PrivateNoCachecacheability is not Private or NoCache.

範例

下列程式碼範例示範如何 Cache-Control 將標頭設定為列舉值 private ,並加入快取控制項延伸模組。The following code example demonstrates how the Cache-Control header is set to the enumeration value private and adds a cache-control extension. 修改的指示詞表示除了任何非共用的快取之外,任何只有名為 "DEV" 的社區成員共用的快取,都可能會快取回應。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")
 

備註

只有當與或指示詞搭配使用時,功能變數名稱副檔名才有效 private no-cacheThe field name extension is valid only when used with the private or no-cache directives. 如需詳細資訊,請參閱 全球資訊網協會 (W3C) 網站上提供的 RFC 2616:超文字傳輸通訊協定--HTTP/1.1。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 在 .NET Framework 版本3.5 中引進。SetCacheability is introduced in the .NET Framework version 3.5. 如需詳細資訊,請參閱版本和相依性For more information, see Versions and Dependencies.

適用於