HttpListener.Prefixes 属性

定义

获取由此 HttpListener 对象处理的统一资源标识符 (URI) 前缀。

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 前缀。

例外

此对象已关闭。

示例

下面的代码示例演示如何使用 Prefixes 属性获取并打印处理的 URI 前缀。

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

注解

前缀采用规范形式。 有关前缀的详细说明,请参阅 HttpListener 类概述。

适用于