Export (0) Print
Expand All

WebRequest.DefaultCachePolicy Property

Note: This property is new in the .NET Framework version 2.0.

Gets or sets the default cache policy for this request.

Namespace: System.Net
Assembly: System (in system.dll)

public static RequestCachePolicy DefaultCachePolicy { get; set; }
/** @property */
public static RequestCachePolicy get_DefaultCachePolicy ()

/** @property */
public static void set_DefaultCachePolicy (RequestCachePolicy value)

public static function get DefaultCachePolicy () : RequestCachePolicy

public static function set DefaultCachePolicy (value : RequestCachePolicy)

Property Value

A HttpRequestCachePolicy that specifies the cache policy in effect for this request when no other policy is applicable.

This policy is used for this request if the following conditions exist:

The cache policy determines whether the requested resource can be taken from a cache instead of sending the request to the resource host computer.

The following code example demonstrates setting the default cache policy for Web requests.

        public static WebResponse GetResponseFromServer2(Uri uri)
{
     RequestCachePolicy policy = 
        new  RequestCachePolicy( RequestCacheLevel.NoCacheNoStore);
    WebRequest request = WebRequest.Create(uri);
    WebRequest.DefaultCachePolicy = policy;
    WebResponse response = request.GetResponse();
    Console.WriteLine("Policy is {0}.", policy.ToString());
    Console.WriteLine("Is the response from the cache? {0}", response.IsFromCache);  
    return response;
} 

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft