This documentation is archived and is not being maintained.

Uri.DnsSafeHost Property

Note: This property is new in the .NET Framework version 2.0.

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

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

public string DnsSafeHost { get; }
/** @property */
public String get_DnsSafeHost ()

public function get DnsSafeHost () : String

Property Value

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 typeCondition


This instance represents a relative URI, and this property is valid only for absolute URIs.

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.         
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]".

// The following outputs "fe80::200:39ff:fe36:1a2d%4".

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

.NET Compact Framework

Supported in: 2.0