WebProxy.IsBypassed(Uri) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指示是否要為指定主機使用 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 使用 Proxy 伺服器,則為 true,否則為 false。
實作
例外狀況
host 參數為 null。
範例
下列程式代碼範例會 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 可用來判斷存取因特網資源時是否略過 Proxy 伺服器。
BypassProxyOnLocal和 BypassList 屬性會控制 方法的IsBypassed傳回值。
IsBypassed 在下列任一情況下會 true 傳回 :
如果 BypassProxyOnLocal 為
true,且host為本機 URI。 本機要求是由 URI 中缺少句點 (.) 來識別,如 中http://webserver/所示。如果
host符合中的 BypassList正則表達式。如果 Address 為
null。
所有其他條件都會傳回 false。