Dil

Uri.Host Özellik

Tanım

Bu örneğin konak bileşenini alır.

public:
 property System::String ^ Host { System::String ^ get(); };
public string Host { get; }
member this.Host : string
Public ReadOnly Property Host As String

Özellik Değeri

Ana bilgisayar adı. Bu genellikle sunucunun DNS ana bilgisayar adı veya IP adresidir.

Özel durumlar

Bu örnek göreli bir URI'yi temsil eder ve bu özellik yalnızca mutlak URI'ler için geçerlidir.

Örnekler

Aşağıdaki örnek, sunucunun ana bilgisayar adını (www.contoso.com) konsola yazar.

Uri baseUri = new Uri("http://www.contoso.com:8080/");
Uri myUri = new Uri(baseUri, "shownew.htm?date=today");

Console.WriteLine(myUri.Host);
let baseUri = Uri "http://www.contoso.com:8080/"
let myUri = Uri(baseUri, "shownew.htm?date=today")

printfn $"{myUri.Host}"
Dim baseUri As New Uri("http://www.contoso.com:8080/")
Dim myUri As New Uri(baseUri,"shownew.htm?date=today")
       
Console.WriteLine(myUri.Host)

Aşağıdaki örnekte DNS, IDN, IPv4 ve Host IPv6 girişleri arasında nasıl IdnHost ve farklı olduğu gösterilmektedir:

// Demonstrate differences between Host, IdnHost, and DnsSafeHost.

// Example 1: Regular hostname (ASCII).
Console.WriteLine("Example 1: Regular ASCII hostname");
Uri uri1 = new Uri("http://www.contoso.com:8080/path");
Console.WriteLine($"  Host:        {uri1.Host}");        // www.contoso.com
Console.WriteLine($"  IdnHost:     {uri1.IdnHost}");     // www.contoso.com
Console.WriteLine($"  DnsSafeHost: {uri1.DnsSafeHost}"); // www.contoso.com
Console.WriteLine();

// Example 2: International domain name (non-ASCII).
Console.WriteLine("Example 2: International domain name");
Uri uri2 = new Uri("http://münchen.de/path");
Console.WriteLine($"  Host:        {uri2.Host}");        // münchen.de (original)
Console.WriteLine($"  IdnHost:     {uri2.IdnHost}");     // xn--mnchen-3ya.de (punycode)
Console.WriteLine($"  DnsSafeHost: {uri2.DnsSafeHost}"); // münchen.de or xn--mnchen-3ya.de, depending on configuration.
Console.WriteLine();

// Example 3: International domain name already in punycode (encoded) form.
Console.WriteLine("Example 3: Already-encoded international domain name");
Uri uri2Encoded = new Uri("http://xn--mnchen-3ya.de/path");
Console.WriteLine($"  Host:        {uri2Encoded.Host}");        // xn--mnchen-3ya.de (as provided)
Console.WriteLine($"  IdnHost:     {uri2Encoded.IdnHost}");     // xn--mnchen-3ya.de (already punycode)
Console.WriteLine($"  DnsSafeHost: {uri2Encoded.DnsSafeHost}"); // xn--mnchen-3ya.de
Console.WriteLine();

// Example 4: IPv6 address without zone ID.
Console.WriteLine("Example 4: IPv6 address without zone ID");
Uri uri3 = new Uri("http://[::1]:8080/path");
Console.WriteLine($"  Host:        {uri3.Host}");        // [::1] (with brackets)
Console.WriteLine($"  IdnHost:     {uri3.IdnHost}");     // ::1 (without brackets)
Console.WriteLine($"  DnsSafeHost: {uri3.DnsSafeHost}"); // ::1 (without brackets)
Console.WriteLine();

// Example 5: IPv6 link-local address with zone ID.
Console.WriteLine("Example 5: IPv6 link-local address with zone ID");
Uri uri4 = new Uri("http://[fe80::1%10]:8080/path");
Console.WriteLine($"  Host:        {uri4.Host}");        // [fe80::1] (with brackets, no zone ID)
Console.WriteLine($"  IdnHost:     {uri4.IdnHost}");     // fe80::1%10 (without brackets, with zone ID)
Console.WriteLine($"  DnsSafeHost: {uri4.DnsSafeHost}"); // fe80::1%10 (without brackets, with zone ID)
Console.WriteLine();

// Example 6: IPv4 address.
Console.WriteLine("Example 6: IPv4 address");
Uri uri5 = new Uri("http://192.168.1.1:8080/path");
Console.WriteLine($"  Host:        {uri5.Host}");        // 192.168.1.1
Console.WriteLine($"  IdnHost:     {uri5.IdnHost}");     // 192.168.1.1
Console.WriteLine($"  DnsSafeHost: {uri5.DnsSafeHost}"); // 192.168.1.1

Açıklamalar

Özelliğin Authority aksine, bu özellik değeri bağlantı noktası numarasını içermez.

Bu özellik tarafından döndürülen değer konak türüne bağlıdır:

  • DNS ana bilgisayar adları için (uluslararası etki alanı adları dahil): Kaçış girişini döndürür. ASCII olmayan karakterler as-is döndürülür ve punycode kodlanmamıştır.
  • IPv6 adresleri için: Köşeli ayraç içine alınmış adresi (örneğin, [::1]) döndürür, ancak özgün URI'de belirtilmiş olsa bile bölge kimliğini (kapsam) içermez.
  • IPv4 adresleri için: Noktalı ondalık gösterimini verir (örneğin, 192.168.1.1).

DNS çözümlemesi veya diğer alt düzey ağ senaryoları için, geçerli uluslararası etki alanı adları için punycode ile kodlanmış bir form döndüren ve IPv6 adresleri için bölge kimliğini (köşeli ayraç olmadan) içeren bunun yerine kullanın IdnHost . Konağı URI'de göründüğü gibi istediğinizde kullanın Host (örneğin, görüntüleme veya karşılaştırma için).

Şunlara uygulanır