Uri.DnsSafeHost Property is the instance property which is used to get a host name unescaped that is safe to use for DNS resolution.
Syntax :
public string DnsSafeHost { get; }
Return Value: This property returns string, it returns the host part of the URI in a format suitable for DNS resolution, if it is already suitable for resolution it returns the original host string.
Exception: This property will give InvalidOperationException if the instance is a relative URI and this property is only valid for the absolute URI’s.
Example 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
// using DnsSafeHost property
Console.WriteLine( "Uri DnsSafeHost: " + v1.DnsSafeHost);
}
} |
Output:
Hostname: www.geeksforgeeks.org
Example 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);
}
} |
Output:
Hostname: docs.microsoft.com`
Article Tags :