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 作为其缓存策略级别。 属性 CachePolicy (如果不是 null)确定对请求生效的缓存策略。 可以使用 属性或计算机或应用程序配置文件中的设置来设置 DefaultCachePolicy 应用程序域的默认策略。 有关详细信息,请参阅 <requestCaching> 元素(网络设置)

适用于