Open In App

Uri.DnsSafeHost Property in C# with Examples

Last Updated : 08 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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  
          
        // using DnsSafeHost property  
        Console.WriteLine("Hostname: "+ v1.DnsSafeHost);  
    }  
}


Output:

Hostname: docs.microsoft.com`


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads