WebProxy.IsBypassed(Uri) 方法

定義

指示是否要為指定主機使用 Proxy 伺服器。

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

要檢查 Proxy 使用之主機 Uri 的執行個體。

傳回

如果不應該為 host 使用 Proxy 伺服器,則為 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 可用來判斷是否要在存取因特網資源時略過 Proxy 伺服器。

BypassProxyOnLocalBypassList 屬性控制 方法的IsBypassed傳回值。

IsBypassedtrue 傳回下列任一條件:

  • 如果 BypassProxyOnLocaltrue ,則為 本機 host URI。 本機要求是由 URI 中缺少期間 (.) 來識別,如 中 http://webserver/所示。

  • 如果 host 符合中的正則 BypassList表達式。

  • 如果 Addressnull

所有其他條件都會傳回 false

適用於