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 检查代理使用的主机实例。

返回

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

实现

例外

参数 hostnull.

示例

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

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在以下任一条件下返回:

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

  • 如果 host 与正则表达式匹配,则为 BypassList..

  • Address如果是null

所有其他条件返回 false

适用于