通过


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 对象获取的资源的缓存行为。

示例

下面的代码示例演示如何显示此属性的值。

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> 元素(网络设置)。

适用于