WebProxy.IsBypassed(Uri) 方法

定义

指示是否对指定的主机使用代理服务器。

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

参数

host
Uri

要检查代理使用情况的主机的 Uri 实例。

返回

如果代理服务器不应用于 host,则为 true;否则,为 false

实现

例外

host 参数为 null

示例

下面的代码示例创建一个 WebProxy 对象,并调用此方法来检查是否已正确设置绕过列表。

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;
    }
}

注解

方法 IsBypassed 用于确定是否在访问 Internet 资源时绕过代理服务器。

BypassProxyOnLocalBypassList 属性控制方法的IsBypassed返回值。

IsBypassed 在以下任一 true 条件下返回 :

  • 如果 BypassProxyOnLocaltruehost 则为本地 URI。 本地请求通过 URI 中缺少句点 (.) 来标识,如 中 http://webserver/所示。

  • 如果 host 与 中的 BypassList正则表达式匹配,

  • 如果 Addressnull

所有其他条件返回 false

适用于