System.Net.WebProxy Class

Assembly: System.dll
Namespace: System.Net
Summary
Contains HTTP proxy settings for the WebRequest class.
C# Syntax:
[Serializable]
public class WebProxy : IWebProxy, ISerializable
Remarks
The WebProxy class contains the proxy settings that WebRequest instances use to override the proxy settings in GlobalProxySelection.

The WebProxy class is the base implementation of the IWebProxy interface.

Example
The following example assigns a WebProxy to a WebRequest. The WebRequest instance uses the proxy to connect to external Internet resources.
WebProxy proxyObject = new WebProxy("http://proxyserver:80/",true);
WebRequest req = WebRequest.Create("http://www.contoso.com");
req.Proxy = proxyObject;


    
See also:
System.Net Namespace

System.Net.WebProxy Member List:

Public Constructors
ctor #1 Overloaded:
.ctor()

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes an empty instance of the WebProxy class.
ctor #2 Overloaded:
.ctor(string Address)

Initializes a new instance of the WebProxy class with the specified URI.
ctor #3 Overloaded:
.ctor(Uri Address)

Initializes a new instance of the WebProxy class from the specified Uri.
ctor #5 Overloaded:
.ctor(string Address, bool BypassOnLocal)

Initializes a new instance of the WebProxy class with the specified URI and bypass setting.
ctor #6 Overloaded:
.ctor(string Host, int Port)

Initializes a new instance of the WebProxy class with the specified host and port number.
ctor #7 Overloaded:
.ctor(Uri Address, bool BypassOnLocal)

Initializes a new instance of the WebProxy class with the Uri and bypass setting.
ctor #8 Overloaded:
.ctor(string Address, bool BypassOnLocal, string[] BypassList)

Initializes a new instance of the WebProxy class with the specified URI, bypass setting, and list of URIs to bypass.
ctor #9 Overloaded:
.ctor(Uri Address, bool BypassOnLocal, string[] BypassList)

Initializes a new instance of the WebProxy class with the specified Uri, bypass setting, and list of URIs to bypass.
ctor #10 Overloaded:
.ctor(string Address, bool BypassOnLocal, string[] BypassList, ICredentials Credentials)

Initializes a new instance of the WebProxy class with the specified URI, bypass setting, list of URIs to bypass, and credentials.
ctor #11 Overloaded:
.ctor(Uri Address, bool BypassOnLocal, string[] BypassList, ICredentials Credentials)

Initializes a new instance of the WebProxy class with the specified Uri, bypass setting, list of URIs to bypass, and credentials.
Public Properties
Address Read-write

Gets or sets the address of the proxy server.
BypassArrayList Read-only

Gets a list of addresses that do not use the proxy server.
BypassList Read-write

Gets or sets an array of addresses that do not use the proxy server.
BypassProxyOnLocal Read-write

Gets or sets a value indicating whether to bypass the proxy server for local addresses.
Credentials Read-write

Gets or sets the credentials to submit to the proxy server for authentication.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetDefaultProxy Reads the Internet Explorer nondynamic proxy settings.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetProxy Returns the proxied URI for a request.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
IsBypassed Indicates whether to use the proxy server for the specified host.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Constructors
ctor #4 Overloaded:
.ctor(SerializationInfo serializationInfo, StreamingContext streamingContext)

Supports the Shared Source CLI infrastructure and is not intended to be used directly from your code
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Net.WebProxy Member Details

Overloaded ctor #1
Summary
Initializes an empty instance of the WebProxy class.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public WebProxy();
Remarks
The default constructor initializes an empty instance of the WebProxy class initializes an empty instance of the WebProxy class with the WebProxy.Address property set to null.

When the WebProxy.Address property is null, the WebProxy.IsBypassed method returns true, and the WebProxy.GetProxy method returns the destination address.

Return to top


Overloaded ctor #2
Summary
Initializes a new instance of the WebProxy class with the specified URI.
C# Syntax:
public WebProxy(
   string Address
);
Parameters:

Address

The URI of the proxy server.

Exceptions
Exception Type Condition
UriFormatException Address is an invalid URI.
Remarks
The WebProxy instance is initialized with the WebProxy.Address property set to a Uri instance containing Address.

Return to top


Overloaded ctor #3
Summary
Initializes a new instance of the WebProxy class from the specified Uri.
C# Syntax:
public WebProxy(
   Uri Address
);
Parameters:

Address

A Uri containing the address of the proxy server.

Remarks
The WebProxy instance is initialized with the WebProxy.Address property set to the Address parameter.

Return to top


Overloaded ctor #4
Summary
Supports the Shared Source CLI infrastructure and is not intended to be used directly from your code
C# Syntax:
protected WebProxy(
   SerializationInfo serializationInfo,
   StreamingContext streamingContext
);
Parameters:

serializationInfo

streamingContext

Return to top


Overloaded ctor #5
Summary
Initializes a new instance of the WebProxy class with the specified URI and bypass setting.
C# Syntax:
public WebProxy(
   string Address,
   bool BypassOnLocal
);
Parameters:

Address

The URI of the proxy server.

BypassOnLocal

true to bypass the proxy for local addresses; otherwise, false.

Exceptions
Exception Type Condition
UriFormatException Address is an invalid URI.
Remarks
The WebProxy instance is initialized with the WebProxy.Address property set to a Uri instance containing Address and the WebProxy.BypassProxyOnLocal property set to BypassOnLocal.
See also:
WebProxy.BypassProxyOnLocal

Return to top


Overloaded ctor #6
Summary
Initializes a new instance of the WebProxy class with the specified host and port number.
C# Syntax:
public WebProxy(
   string Host,
   int Port
);
Parameters:

Host

The name of the proxy host.

Port

The port number on Host to use.

Exceptions
Exception Type Condition
UriFormatException The URI formed by combining Host and Port is not a valid URI.
Remarks
The WebProxy instance is initialized with the WebProxy.Address property set to a Uri instance of the form http:// Host: Port.

Return to top


Overloaded ctor #7
Summary
Initializes a new instance of the WebProxy class with the Uri and bypass setting.
C# Syntax:
public WebProxy(
   Uri Address,
   bool BypassOnLocal
);
Parameters:

Address

A Uri containing the address of the proxy server.

BypassOnLocal

true to bypass the proxy for local addresses; otherwise, false.

Remarks
The WebProxy instance is initialized with the WebProxy.Address property set to Address and with the WebProxy.BypassProxyOnLocal property set to BypassOnLocal.

Return to top


Overloaded ctor #8
Summary
Initializes a new instance of the WebProxy class with the specified URI, bypass setting, and list of URIs to bypass.
C# Syntax:
public WebProxy(
   string Address,
   bool BypassOnLocal,
   string[] BypassList
);
Parameters:

Address

The URI of the proxy server.

BypassOnLocal

true to bypass the proxy for local addresses; otherwise, false.

BypassList

An array of regular expression strings containing the URIs of the servers to bypass.

Exceptions
Exception Type Condition
UriFormatException Address is an invalid URI.
Remarks
The WebProxy instance is initialized with the WebProxy.Address property set to a Uri instance containing Address, the WebProxy.BypassProxyOnLocal property set to BypassOnLocal, and the WebProxy.BypassList property set to BypassList.
See also:
WebProxy.BypassProxyOnLocal | WebProxy.BypassList

Return to top


Overloaded ctor #9
Summary
Initializes a new instance of the WebProxy class with the specified Uri, bypass setting, and list of URIs to bypass.
C# Syntax:
public WebProxy(
   Uri Address,
   bool BypassOnLocal,
   string[] BypassList
);
Parameters:

Address

A Uri containing the address of the proxy server.

BypassOnLocal

true to bypass the proxy for local addresses; otherwise, false.

BypassList

An array of regular expression strings containing the URIs of the servers to bypass.

Remarks
The WebProxy instance is initialized with the WebProxy.Address property set to Address, the WebProxy.BypassProxyOnLocal property set to BypassOnLocal, and the WebProxy.BypassList property set to BypassList.

Return to top


Overloaded ctor #10
Summary
Initializes a new instance of the WebProxy class with the specified URI, bypass setting, list of URIs to bypass, and credentials.
C# Syntax:
public WebProxy(
   string Address,
   bool BypassOnLocal,
   string[] BypassList,
   ICredentials Credentials
);
Parameters:

Address

The URI of the proxy server.

BypassOnLocal

true to bypass the proxy for local addresses; otherwise, false.

BypassList

An array of regular expression strings containing the URIs of the servers to bypass.

Credentials

An ICredentials to submit to the proxy server for authentication.

Exceptions
Exception Type Condition
UriFormatException Address is an invalid URI.
Remarks
The WebProxy instance is initialized with the WebProxy.Address property set to a Uri instance containing Address, the WebProxy.BypassProxyOnLocal property set to BypassOnLocal, the WebProxy.BypassList property set to BypassList, and the WebProxy.Credentials property set to Credentials.
See also:
WebProxy.BypassProxyOnLocal | WebProxy.BypassList

Return to top


Overloaded ctor #11
Summary
Initializes a new instance of the WebProxy class with the specified Uri, bypass setting, list of URIs to bypass, and credentials.
C# Syntax:
public WebProxy(
   Uri Address,
   bool BypassOnLocal,
   string[] BypassList,
   ICredentials Credentials
);
Parameters:

Address

A Uri containing the address of the proxy server.

BypassOnLocal

true to bypass the proxy for local addresses; otherwise, false.

BypassList

An array of regular expression strings containing the URIs of the servers to bypass.

Credentials

An ICredentials to submit to the proxy server for authentication.

Remarks
The WebProxy instance is initialized with the WebProxy.Address property set to Address, the WebProxy.BypassProxyOnLocal property set to BypassOnLocal, the WebProxy.BypassList property set to BypassList, and the WebProxy.Credentials property set to Credentials

Return to top


Property: Address (read-write)
Summary
Gets or sets the address of the proxy server.
C# Syntax:
public Uri Address {get; set;}
Remarks
The WebProxy.Address property contains the address of the proxy server. When WebProxy.Address is null, all requests bypass the proxy and connect directly to the destination host.

Return to top


Property: BypassArrayList (read-only)
Summary
Gets a list of addresses that do not use the proxy server.
C# Syntax:
public ArrayList BypassArrayList {get;}
Remarks
The WebProxy.BypassList property contains an array list of regular expression strings that describe the URIs that a WebRequest instance accesses directly instead of through the proxy server.

Return to top


Property: BypassList (read-write)
Summary
Gets or sets an array of addresses that do not use the proxy server.
C# Syntax:
public string[] BypassList {get; set;}
Remarks
The WebProxy.BypassList property contains an array of regular expressions that describe URIs that a WebRequest instance accesses directly instead of through the proxy server.
See also:
Regex

Return to top


Property: BypassProxyOnLocal (read-write)
Summary
Gets or sets a value indicating whether to bypass the proxy server for local addresses.
C# Syntax:
public bool BypassProxyOnLocal {get; set;}
Remarks
The setting of the WebProxy.BypassProxyOnLocal property determines whether WebRequest instances use the proxy server when accessing local Internet resources.

If WebProxy.BypassProxyOnLocal is true, requests to local Internet resources do not use the proxy server. Local requests are identified by the lack of a period (.) in the URI, as in http://webserver/ or access the local server, including http://localhost, http://loopback, or http://127.0.0.1 . When WebProxy.BypassProxyOnLocal is false, all Internet requests are made through the proxy server.



Note Requests to a local host with a URI containing a period use the proxy. To avoid using a proxy in these cases, create an entry for the host in the WebProxy.BypassList.

Return to top


Property: Credentials (read-write)
Summary
Gets or sets the credentials to submit to the proxy server for authentication.
C# Syntax:
public ICredentials Credentials {get; set;}
Implements:
IWebProxy.Credentials
Remarks
The WebProxy.Credentials property contains the authentication credentials to send to the proxy server in response to an HTTP 407 (proxy authorization) status code.

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~WebProxy();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetDefaultProxy()
Summary
Reads the Internet Explorer nondynamic proxy settings.
C# Syntax:
public static WebProxy GetDefaultProxy();
Return Value:
A WebProxy instance containing the nondynamic proxy settings from Internet Explorer 5.5.
Remarks
The WebProxy.GetDefaultProxy method reads the nondynamic proxy settings stored by Internet Explorer 5.5 and creates a WebProxy instance with those settings.

The WebProxy.GetDefaultProxy does not pick up any dynamic settings that are generated from script run by Internet Explorer, from automatic configuration entries, or from DHCP or DNS lookups.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetProxy(
   Uri destination
)
Summary
Returns the proxied URI for a request.
C# Syntax:
public Uri GetProxy(
   Uri destination
);
Parameters:

destination

The Uri of the requested Internet resource.

Return Value:
The Uri of the Internet resource, if the resource is on the bypass list; otherwise, the Uri of the proxy.
Implements:
IWebProxy.GetProxy
Remarks
The WebProxy.GetProxy method returns the URI that the WebRequest uses to access the Internet resource.

WebProxy.GetProxy compares destination with the contents of WebProxy.BypassList using the WebProxy.IsBypassed method. If WebProxy.IsBypassed returns true, WebProxy.GetProxy returns destination and the WebRequest does not use the proxy server.

If destination is not in WebProxy.BypassList, the WebRequest uses the proxy server, and the WebProxy.Address property is returned.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: IsBypassed(
   Uri host
)
Summary
Indicates whether to use the proxy server for the specified host.
C# Syntax:
public bool IsBypassed(
   Uri host
);
Parameters:

host

The Uri of the host to check for proxy use.

Return Value:
true if the proxy server should not be used for host; otherwise, false.
Implements:
IWebProxy.IsBypassed
Remarks
The WebProxy.IsBypassed method is used to determine whether to bypass the proxy server when accessing an Internet resource.

The WebProxy.BypassProxyOnLocal and WebProxy.BypassList properties control the return value of the WebProxy.IsBypassed method.

WebProxy.IsBypassed returns true under any of the following conditions.

All other conditions return false.

.NET Framework Security:
ArgumentException WebProxy.BypassList contains an invalid regular expression.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.