Uri.DnsSafeHost Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets an unescaped host name that is safe to use for DNS resolution.

Namespace:  System
Assembly:  System (in System.dll)


Public ReadOnly Property DnsSafeHost As String
public string DnsSafeHost { get; }

Property Value

Type: System.String
A String that contains the unescaped host part of the URI that is suitable for DNS resolution; or the original unescaped host string, if it is already suitable for resolution.


Exception Condition

This property is valid only for an absolute Uri instance.


For IPv6 addresses, the brackets ([]) are removed and the ScopeId property is set, if one was specified when this instance was constructed.


The following example creates a Uri instance from a string. It illustrates the difference between the value returned from Host, which returns the host name or address specified in the URI, and the value returned from DnsSafeHost, which returns an address that is safe to use in DNS resolution.

' Create new Uri using a string address.         
Dim address As Uri = new Uri("http://[fe80::200:39ff:fe36:1a2d%4]/temp/example.htm")

' Make the address DNS safe. 

' The following outputs "[fe80::200:39ff:fe36:1a2d]".
outputBlock.Text &= address.Host
outputBlock.Text &= vbCrLf

' The following outputs "fe80::200:39ff:fe36:1a2d%4".
outputBlock.Text &= address.DnsSafeHost
outputBlock.Text &= vbCrLf
// Create new Uri using a string address.         
Uri address = new Uri("http://[fe80::200:39ff:fe36:1a2d%4]/temp/example.htm");

// Make the address DNS safe. 

// The following outputs "[fe80::200:39ff:fe36:1a2d]".
outputBlock.Text += address.Host;
outputBlock.Text += "\n";

// The following outputs "fe80::200:39ff:fe36:1a2d%4".
outputBlock.Text += address.DnsSafeHost;
outputBlock.Text += "\n";

Version Information


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0


For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also