Uri.CheckHostName(String) Method

Definition

判斷指定的主機名稱是否為有效的 DNS 名稱。Determines whether the specified host name is a valid DNS name.

public:
 static UriHostNameType CheckHostName(System::String ^ name);
public static UriHostNameType CheckHostName (string name);
static member CheckHostName : string -> UriHostNameType
Public Shared Function CheckHostName (name As String) As UriHostNameType

Parameters

name
String

要驗證的主機名稱。The host name to validate. 這可以是 IPv4 或 IPv6 位址或網際網路主機名稱。This can be an IPv4 or IPv6 address or an Internet host name.

Returns

UriHostNameType

UriHostNameType,表示主機名稱的類型。A UriHostNameType that indicates the type of the host name. 當無法判斷主機名稱類型,或主機名稱為 null 或長度為零的字串時,這個方法會傳回 UnknownIf the type of the host name cannot be determined or if the host name is null or a zero-length string, this method returns Unknown.

Examples

下列範例會檢查主機名稱是否有效。The following example checks whether the host name is valid.

Console::WriteLine( Uri::CheckHostName( "www.contoso.com" ) );
Console.WriteLine(Uri.CheckHostName("www.contoso.com"));

Console.WriteLine(Uri.CheckHostName("www.contoso.com"))

Remarks

CheckHostName 方法會檢查所提供的主機名稱是否符合有效網際網路主機名稱的需求。The CheckHostName method checks that the host name provided meets the requirements for a valid Internet host name. 不過,它不會執行主機名稱查詢來驗證主機是否存在。It does not, however, perform a host-name lookup to verify the existence of the host.

Applies to