HttpListener.Prefixes HttpListener.Prefixes HttpListener.Prefixes HttpListener.Prefixes Property

定義

取得這個 HttpListener 物件所處理的統一資源識別元 (URI) 前置詞。Gets the Uniform Resource Identifier (URI) prefixes handled by this HttpListener object.

public:
 property System::Net::HttpListenerPrefixCollection ^ Prefixes { System::Net::HttpListenerPrefixCollection ^ get(); };
public System.Net.HttpListenerPrefixCollection Prefixes { get; }
member this.Prefixes : System.Net.HttpListenerPrefixCollection
Public ReadOnly Property Prefixes As HttpListenerPrefixCollection

屬性值

HttpListenerPrefixCollection,包含這個 HttpListener 物件設定可處理的 URI 前置詞。An HttpListenerPrefixCollection that contains the URI prefixes that this HttpListener object is configured to handle.

例外狀況

範例

下列程式碼範例將示範如何Prefixes使用屬性來取得和列印已處理的 URI 前置詞。The following code example demonstrates using the Prefixes property to obtain and print the URI prefixes that are handled.

public static void DisplayPrefixesAndState(HttpListener listener)
{
    // List the prefixes to which the server listens.
    HttpListenerPrefixCollection prefixes = listener.Prefixes;
    if (prefixes.Count == 0)
    {
        Console.WriteLine("There are no prefixes.");
    }
    foreach(string prefix in prefixes)
    {
        Console.WriteLine(prefix);
    }
    // Show the listening state.
    if (listener.IsListening)
    {
        Console.WriteLine("The server is listening.");
    }
}
Public Shared Sub DisplayPrefixesAndState(ByVal listener As HttpListener)
    ' List the prefixes to which the server listens.
    Dim prefixes As HttpListenerPrefixCollection = listener.Prefixes

    If prefixes.Count = 0 Then
        Console.WriteLine("There are no prefixes.")
    End If

    For Each prefix As String In prefixes
        Console.WriteLine(prefix)
    Next

    ' Show the listening state.
    If listener.IsListening Then
        Console.WriteLine("The server is listening.")
    End If
End Sub

備註

首碼是標準格式。The prefixes are in canonical form. 如需首碼的詳細描述, 請參閱HttpListener類別總覽。For a detailed description of prefixes, see the HttpListener class overview.

適用於