Redigera

Dela via


WebProxy.IsBypassed(Uri) Method

Definition

Indicates whether to use the proxy server for the specified host.

public:
 virtual bool IsBypassed(Uri ^ host);
public bool IsBypassed (Uri host);
abstract member IsBypassed : Uri -> bool
override this.IsBypassed : Uri -> bool
Public Function IsBypassed (host As Uri) As Boolean

Parameters

host
Uri

The Uri instance of the host to check for proxy use.

Returns

true if the proxy server should not be used for host; otherwise, false.

Implements

Exceptions

The host parameter is null.

Examples

The following code example creates a WebProxy object and calls this method to check whether the bypass list is properly set.

WebProxy^ CreateProxyAndCheckBypass( bool bypassLocal )
{
   // Do not use the proxy server for Contoso.com URIs.
   array<String^>^ bypassList = {";*.Contoso.com"};
   WebProxy^ proxy = gcnew WebProxy( "http://contoso",
      bypassLocal,
      bypassList );
   
   // Test the bypass list.
   if (  !proxy->IsBypassed( gcnew Uri( "http://www.Contoso.com" ) ) )
   {
      Console::WriteLine( "Bypass not working!" );
      return nullptr;
   }
   else
   {
      Console::WriteLine( "Bypass is working." );
      return proxy;
   }
}
public static WebProxy CreateProxyAndCheckBypass(bool bypassLocal)
{
    // Do not use the proxy server for Contoso.com URIs.
    string[] bypassList = new string[]{";*.Contoso.com"};
    WebProxy proxy =  new WebProxy("http://contoso",
        bypassLocal,
        bypassList);

    // Test the bypass list.
    if (!proxy.IsBypassed(new Uri("http://www.Contoso.com")))
    {
        Console.WriteLine("Bypass not working!");
        return null;
    }
    else
    {
        Console.WriteLine("Bypass is working.");
        return proxy;
    }
}

Remarks

The IsBypassed method is used to determine whether to bypass the proxy server when accessing an Internet resource.

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

IsBypassed returns true under any of the following conditions:

  • If BypassProxyOnLocal is true and host is a local URI. Local requests are identified by the lack of a period (.) in the URI, as in http://webserver/.

  • If host matches a regular expression in BypassList.

  • If Address is null.

All other conditions return false.

Applies to