Bagikan melalui


WebProxy.IsBypassed(Uri) Metode

Definisi

Menunjukkan apakah akan menggunakan server proksi untuk host yang ditentukan.

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

Parameter

host
Uri

Uri Instans host untuk memeriksa penggunaan proksi.

Mengembalikan

true jika server proksi tidak boleh digunakan untuk host; jika tidak, false.

Penerapan

Pengecualian

Parameternya host adalah null.

Contoh

Contoh kode berikut membuat WebProxy objek dan memanggil metode ini untuk memeriksa apakah daftar bypass diatur dengan benar.

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

Keterangan

Metode IsBypassed ini digunakan untuk menentukan apakah akan melewati server proksi saat mengakses sumber daya Internet.

Properti BypassProxyOnLocal dan BypassList mengontrol nilai IsBypassed pengembalian metode.

IsBypassedtrue dikembalikan dalam salah satu kondisi berikut:

  • Jika BypassProxyOnLocal adalah true dan host adalah URI lokal. Permintaan lokal diidentifikasi oleh kurangnya titik (.) dalam URI, seperti dalam http://webserver/.

  • Jika host cocok dengan ekspresi reguler di BypassList.

  • Jika Address adalah null.

Semua kondisi lainnya mengembalikan false.

Berlaku untuk