Home »
C#
C# | Uri.DnsSafeHost Property with Example
Uri.DnsSafeHost Property: Here, we are going to learn about the DnsSafeHost Property of Uri class with example in C#.
Submitted by Nidhi, on March 28, 2020
Uri.DnsSafeHost Property
Uri.DnsSafeHost Property is the instance property of Uri class which used to get a un-escaped hostname that is safe to use in DNS resolution. This property returns a string value. This property may generate System.InvalidOperationException exception.
Syntax:
public string DnsSafeHost { get; }
Return value:
The return type of this property is string, it returns the host part of the URI in a format suitable for DNS resolution; or the original host string, if it is already suitable for resolution.
Example to demonstrate example of Uri.DnsSafeHost Property
using System;
class UriExample
{
//Entry point of Program
static public void Main()
{
Uri domainUri;
domainUri = new Uri("https://www.includehelp.com:8082");
Console.WriteLine("Hostname: "+ domainUri.DnsSafeHost);
}
}
Output
Hostname: www.includehelp.com
In the above program, we created an object of Uri class initialized with the website name with port number and we got a un-escaped hostname using DnsSafeHost property.
Reference: Uri.DnsSafeHost Property