Uri.DnsSafeHost 屬性是用於獲取可安全用於 DNS 解析的未轉義主機名的實例屬性。
用法:
public string DnsSafeHost { get; }
返回值:此屬性返回字符串,它以適合 DNS 解析的格式返回 URI 的主機部分,如果它已經適合解析,則返回原始主機字符串。
異常:如果實例是相對 URI 並且此屬性僅對絕對 URI 有效,則此屬性將給出 InvalidOperationException。
範例1:
C#
// C# program to demonstrate the
// Uri.DnsSafeHost property
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main() {
// Declaring and initializing value1
Uri v1 = new Uri("https://www.geeksforgeeks.org/greedy-algorithms/#standardGreedyAlgorithms");
// using DnsSafeHost property
Console.WriteLine("Uri DnsSafeHost:" + v1.DnsSafeHost);
}
}
輸出:
Hostname:www.geeksforgeeks.org
範例2:
C#
// C# program to demonstrate the
// Uri.DnsSafeHost property
using System;
using System.Globalization;
class GFG {
// Main Method
public static void Main()
{
// Declaring and initializing value1
Uri v1 = new Uri("https://docs.microsoft.com/en-us/dotnet/api/system.uri.isloopback?view=netcore-3.1");
// using DnsSafeHost property
Console.WriteLine("Hostname:"+ v1.DnsSafeHost);
}
}
輸出:
Hostname:docs.microsoft.com`
相關用法
- C# Console.TreatControlCAsInput用法及代碼示例
- C# Uri.Fragment用法及代碼示例
- C# StringBuilder.Chars[]用法及代碼示例
- C# Thread.CurrentThread用法及代碼示例
- C# Dictionary.Item[]用法及代碼示例
- C# Dictionary.Values用法及代碼示例
- C# Dictionary.Keys用法及代碼示例
- C# Dictionary.Count用法及代碼示例
- C# SortedDictionary.Item[]用法及代碼示例
- C# SortedDictionary.Count用法及代碼示例
- C# SortedDictionary.Keys用法及代碼示例
- C# SortedDictionary.Values用法及代碼示例
- C# Queue.Count用法及代碼示例
- C# Queue.IsSynchronized用法及代碼示例
- C# Stack.Count用法及代碼示例
- C# Stack.IsSynchronized用法及代碼示例
- C# Array.GetValue()方法用法及代碼示例
- C# File.GetLastWriteTimeUtc()用法及代碼示例
注:本文由純淨天空篩選整理自shivanisinghss2110大神的英文原創作品 Uri.DnsSafeHost Property in C# with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。