Uri.DnsSafeHost Property in C# with Examples

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#

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
  }
}

chevron_right


Output:

Hostname: www.geeksforgeeks.org

Example 2:

C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);  
    }  
}

chevron_right


Output:

Hostname: docs.microsoft.com`



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.