HttpRequestCachePolicy.Level 屬性


取得建立這個執行個體時所指定的 HttpRequestCacheLevel 值。Gets the HttpRequestCacheLevel value that was specified when this instance was created.

 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 物件取得之資源的快取行為。A HttpRequestCacheLevel value that specifies the cache behavior for resources that were obtained using HttpWebRequest objects.


下列程式碼範例將示範如何顯示此屬性的值。The following code example demonstrates displaying the value of this property.

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 做為其快取原則層級。Applications typically use Default as their cache policy level. CachePolicy 屬性(如果不是 null)會決定對要求有效的快取原則。The CachePolicy property, if not null, determines the cache policy in effect for a request. 應用程式域的預設原則可以使用 [DefaultCachePolicy] 屬性或電腦或應用程式佈建檔中的設定來設定。The default policy for the application domain can be set using the DefaultCachePolicy property or by settings in the machine or application configuration files. 如需詳細資訊,請參閱<requestcaching>> 元素(網路設定)For more information, see <requestCaching> Element (Network Settings).