System.Net.WebProxy Class

Contains HTTP proxy settings for the System.Net.WebRequest class.

See Also: WebProxy Members


public class WebProxy : IWebProxy, System.Runtime.Serialization.ISerializable


The System.Net.WebProxy class contains the proxy settings that System.Net.WebRequest instances use to determine whether a Web proxy is used to send requests. Global Web proxy settings can be specified in machine and application configuration files, and applications can use instances of the System.Net.WebProxy class to customize Web proxy use. The System.Net.WebProxy class is the base implementation of the System.Net.IWebProxy interface.

To obtain instances of the Web proxy class, you can use any of the following methods:

These methods each supply a System.Net.WebProxy instance that you can further customize; the difference between them is how the instance is initialized before it is returned to your application. The WebProxy.#ctor constructor returns an instance of the System.Net.WebProxy class with the WebProxy.Address property set to null. When a request uses a System.Net.WebProxy instance in this state, no proxy is used to send the request.

The WebProxy.GetDefaultProxy method returns an instance of the System.Net.WebProxy class with the WebProxy.Address, WebProxy.BypassProxyOnLocal, and WebProxy.BypassList properties set to the values used by Internet Explorer 5.5 and later.

The GlobalProxySelection.Select method returns an instance of the System.Net.WebProxy class with it properties set according to a combination of Internet Explorer and configuration file settings.

The System.Net.WebProxy class supports automatic detection and execution of proxy configuration scripts. This feature is also known as Web Proxy Auto-Discovery (WPAD). When using automatic proxy configuration, a configuration script, typically named Wpad.dat, must be located, downloaded, compiled, and run. If these operations are successful, the script returns the proxies that can be used for a request.

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.


The following example sets a System.Net.WebProxy for a System.Net.WebRequest. The System.Net.WebRequest instance uses the proxy to connect to external Internet resources.

C# Example

using System;
using System.Net;

public class WebProxyExample {

  public static void Main() {

    WebProxy proxyObject =
      new WebProxy("http://proxyserver:80/",true);
    WebRequest req =
    req.Proxy = proxyObject;


Namespace: System.Net
Assembly: System (in System.dll)
Assembly Versions: 1.0.x.x, 1.0.5000.0,,