共用方式為


HttpRequestCachePolicy.Level 屬性

定義

取得建立這個執行個體時所指定的 HttpRequestCacheLevel 值。

public:
 property System::Net::Cache::HttpRequestCacheLevel Level { System::Net::Cache::HttpRequestCacheLevel get(); };
public System.Net.Cache.HttpRequestCacheLevel Level { get; }
member this.Level : System.Net.Cache.HttpRequestCacheLevel
Public ReadOnly Property Level As HttpRequestCacheLevel

屬性值

HttpRequestCacheLevel 值,指定使用 HttpWebRequest 物件取得之資源的快取行為。

範例

下列程式代碼範例示範如何顯示這個屬性的值。

static WebResponse^ GetResponseUsingCacheDefault( Uri^ uri )
{
   // Set  the default cache policy level for the "http:" scheme.
   RequestCachePolicy^ policy = gcnew RequestCachePolicy;

   // Create the request.
   WebRequest^ request = WebRequest::Create( uri );
   request->CachePolicy = policy;
   WebResponse^ response = request->GetResponse();
   Console::WriteLine( L"Policy level is {0}.", policy->Level );
   Console::WriteLine( L"Is the response from the cache? {0}", response->IsFromCache );
   return response;
}
public static WebResponse GetResponseUsingCacheDefault(Uri uri)
{
    // Set  the default cache policy level for the "http:" scheme.
    RequestCachePolicy policy = new RequestCachePolicy();
    // Create the request.
    WebRequest request = WebRequest.Create(uri);
    request.CachePolicy = policy;
    WebResponse response = request.GetResponse();
    Console.WriteLine("Policy level is {0}.", policy.Level.ToString());
    Console.WriteLine("Is the response from the cache? {0}", response.IsFromCache);

    return response;
}

備註

應用程式通常會使用 Default 作為其快取原則層級。 如果不是 null,則CachePolicy屬性會決定要求生效的快取原則。 您可以使用 屬性或計算機或應用程式組態檔中的設定,來設定 DefaultCachePolicy 應用程式域的默認原則。 如需詳細資訊,請參閱 <requestCaching> 元素 (網路設定)

適用於