Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

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#




// 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`



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!