This documentation is archived and is not being maintained.

IWebProxy.Credentials Property

The credentials to submit to the proxy server for authentication.

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

ICredentials Credentials { get; set; }
/** @property */
ICredentials get_Credentials ()

/** @property */
void set_Credentials (ICredentials value)

function get Credentials () : ICredentials

function set Credentials (value : ICredentials)

Not applicable.

Property Value

An ICredentials instance that contains the credentials that are needed to authenticate a request to the proxy server.

The Credentials property is an ICredentials instance that contains the authorization credentials to send to the proxy server in response to an HTTP 407 (proxy authorization) status code.

The following example uses the Credentials property to set the credentials that will be submitted to the proxy server for authentication.

public class WebProxy_Interface : IWebProxy

{

	// The credentials to be used with the web proxy.
	private ICredentials iCredentials;

	// Uri of the associated proxy server.
	private Uri webProxyUri;

	public WebProxy_Interface(Uri proxyUri) {

		webProxyUri = proxyUri;	

	}

	// Get and Set the Credentials property.
	public ICredentials Credentials {
		get {
			return iCredentials;
		}
		set {
			if(iCredentials != value)
				iCredentials = value;
		}
	}

	// Return the web proxy for the specified destination(destUri).
	public Uri GetProxy(Uri destUri) {

		// Always use the same proxy.
		return webProxyUri;

	}

	// Return whether the web proxy should be bypassed for the specified destination(hostUri).
	public bool IsBypassed(Uri hostUri) {

		// Never bypass the proxy.
		return false;

	}
};

public class WebProxyInterface implements IWebProxy
{
    // The credentials to be used with the web proxy.
    private ICredentials iCredentials;
    // Uri of the associated proxy server.
    private Uri webProxyUri;

    public WebProxyInterface(Uri proxyUri) 
    {
        webProxyUri = proxyUri;
    } //WebProxyInterface 
   
    // Get and Set the Credentials property.
   
    /** @property 
     */
    public ICredentials get_Credentials()
    {
        return iCredentials ;
    } //get_Credentials

    /** @property 
     */
    public void set_Credentials (ICredentials value)
    {
        if (iCredentials != value) {
            iCredentials = value;
        }
    } //set_Credentials
   
    // Return the web proxy for the specified destination(destUri).
    public Uri GetProxy(Uri destUri) 
    {
        // Always use the same proxy.
        return webProxyUri ;
    } //GetProxy

    // Return whether the web proxy should be bypassed for the specified
    //destination(hostUri).
    public boolean IsBypassed(Uri hostUri) 
    {
        // Never bypass the proxy.
        return false ;
    } //IsBypassed 
} //WebProxyInterface

Windows 98, Windows Server 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 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, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Show: