WebRequest.DefaultCachePolicy Property

Gets or sets the default cache policy for this request.

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

static property RequestCachePolicy^ DefaultCachePolicy {
	RequestCachePolicy^ get ();
	void set (RequestCachePolicy^ value);
/** @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)

Not applicable.

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:

  • There is no DefaultCachePolicy property specified for this request.

  • The machine and application configuration files do not specify a cache policy that is applicable to the Uniform Resource Identifier (URI) used to create this request.

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 Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions