Uri.DnsSafeHost Property in C# with Examples
Last Updated :
08 Jun, 2020
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#
using System;
using System.Globalization;
class GFG {
public static void Main() {
Console.WriteLine( "Uri DnsSafeHost: " + v1.DnsSafeHost);
}
}
|
Output:
Hostname: www.geeksforgeeks.org
Example 2:
C#
using System;
using System.Globalization;
class GFG {
public static void Main()
{
Console.WriteLine( "Hostname: " + v1.DnsSafeHost);
}
}
|
Output:
Hostname: docs.microsoft.com`
Share your thoughts in the comments
Please Login to comment...