Try our conversational search powered by Generative AI!

Class Url

Extend and wrap the System.Uri class, forming an Url class, where the assumption is that all relative Uri's are actually relative http: scheme Url's. Use like System.Uri, but you do not need to separate between relative and absolute.

Inheritance
System.Object
Url
Implements
System.Xml.Serialization.IXmlSerializable
Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer
Assembly: EPiServer.dll
Version: 11.20.7
Syntax
public class Url : IXmlSerializable

Constructors

Url(Url)

Initializes a new instance of the Url class.

Declaration
protected Url(Url url)
Parameters
Type Name Description
Url url

The URL.

Url(String)

Initializes a new instance of the Url class.

Declaration
public Url(string url)
Parameters
Type Name Description
System.String url

The URL.

Url(Uri)

Initializes a new instance of the Url class.

Declaration
public Url(Uri uri)
Parameters
Type Name Description
System.Uri uri

The URI.

Properties

Authority

Gets the Domain Name System (DNS) host name or IP address and the port number for a server.

Declaration
public string Authority { get; }
Property Value
Type Description
System.String

A string containing the authority component of the URI represented by this instance.

DnsSafeHost

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

Declaration
public string DnsSafeHost { get; }
Property Value
Type Description
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.

Encoding

Gets the encoding used for unescaping and escaping.

Declaration
public Encoding Encoding { get; set; }
Property Value
Type Description
System.Text.Encoding

The encoding. The default is UTF-8.

Fragment

Gets the escaped fragment.

Declaration
public string Fragment { get; }
Property Value
Type Description
System.String

A string containing any URI fragment information.

Host

Gets the host component of this instance.

Declaration
public string Host { get; }
Property Value
Type Description
System.String

A String containing the host name. This is usually the DNS host name or IP address of the server.

IsAbsoluteUri

Gets a value indicating whether this instance is absolute.

Declaration
public bool IsAbsoluteUri { get; }
Property Value
Type Description
System.Boolean

true if this instance is absolute; otherwise, false.

IsRelative

Gets or sets a value indicating whether this Url instance represents a relative Url.

Declaration
protected bool IsRelative { get; set; }
Property Value
Type Description
System.Boolean

true if this instance is relative; otherwise, false.

LocalPath

Gets a local operating-system representation of a file name.

Declaration
public string LocalPath { get; }
Property Value
Type Description
System.String

A string containing the local operating-system representation of a file name.

OriginalString

Gets or sets the original string.

Declaration
public string OriginalString { get; }
Property Value
Type Description
System.String

The original string.

Path

Gets the path. Will return a relative path if the path was relative to start with.

Declaration
public string Path { get; }
Property Value
Type Description
System.String

The path.

PathAndQuery

Gets the AbsolutePath and Query properties separated by a question mark (?).

Declaration
public string PathAndQuery { get; }
Property Value
Type Description
System.String

A String that contains the AbsolutePath and Query properties separated by a question mark (?).

Port

Gets the port number of this URL.

Declaration
public int Port { get; }
Property Value
Type Description
System.Int32

An int value containing the port number for this URL.

Remarks

If the URL is relative, the port is reported as -1, meaning "Not applicable". The port for a relative URL will be the same as the port of the URL that this URL is relative to.

Query

Gets any query information included in the specified URL.

Declaration
public string Query { get; }
Property Value
Type Description
System.String

A String containing any query information included in the specified URL.

Remarks

The Query property contains any query information included in the URI. Query information is separated from the path information by a question mark (?) and continues to the end of the URI. The query information returned includes the leading question mark. The query information is escaped according to RFC 2396.

QueryCollection

Gets a parsed and decoded collection of query string parameters.

Declaration
public NameValueCollection QueryCollection { get; }
Property Value
Type Description
System.Collections.Specialized.NameValueCollection

The query collection.

Scheme

Gets the scheme name for this URL.

Declaration
public string Scheme { get; }
Property Value
Type Description
System.String

A String containing the scheme for this URL, converted to lowercase.

Segments

Gets an array containing the path segments that make up the specified URL.

Declaration
public string[] Segments { get; }
Property Value
Type Description
System.String[]

A String array containing the path segments that make up the specified URL.

Split

Gets the different components of the Url

Declaration
protected string[] Split { get; }
Property Value
Type Description
System.String[]

The split.

Uri

Gets the backing System.Uri.

Declaration
public Uri Uri { get; }
Property Value
Type Description
System.Uri

The Uri instance

UriInternal

Gets the internal System.Uri, which is always absolute possibly by prefixing the original relative Url with http://localhost .

Declaration
protected Uri UriInternal { get; }
Property Value
Type Description
System.Uri

The internal System.Uri, always absolute. Check IsRelative before use.

UserEscaped

Indicates that the URI string was completely escaped before the Url instance was created.

Declaration
public bool UserEscaped { get; }
Property Value
Type Description
System.Boolean

true if the dontEscape parameter was set to true when the Uri instance was created; otherwise, false.

UserInfo

Gets the user name, password, or other user-specific information associated with the specified URL.

Declaration
public string UserInfo { get; }
Property Value
Type Description
System.String

A String containing the user information associated with the URL. The returned value does not include the '@' character reserved for delimiting the user information part of the URL.

Methods

Decode(String)

Decodes the specified string assuming UTF8.

Declaration
public static string Decode(string s)
Parameters
Type Name Description
System.String s

The URL encoded string.

Returns
Type Description
System.String

The decoded string

Remarks

Will decode %xx, %uxxxx and convert + to space.

Decode(String, Encoding)

Decodes the specified string with the given encoding.

Declaration
public static string Decode(string s, Encoding e)
Parameters
Type Name Description
System.String s

The URL encoded string.

System.Text.Encoding e

The encoding.

Returns
Type Description
System.String

The decoded string.

Remarks

Will decode %xx, %uxxxx and convert + to space.

Decode(String, Encoding, Url.DecodeOptions)

Decodes the specified string with the given encoding.

Declaration
public static string Decode(string s, Encoding e, Url.DecodeOptions options)
Parameters
Type Name Description
System.String s

The URL encoded string.

System.Text.Encoding e

The encoding.

Url.DecodeOptions options

The decode options to use.

Returns
Type Description
System.String

The decoded string.

Remarks

The Url.DecodeOptions allows you to determine which types of encodings to decode.

Encode(String)

Encodes the specified string.

Declaration
public static string Encode(string str)
Parameters
Type Name Description
System.String str

The string to encode.

Returns
Type Description
System.String

An encoded string.

Remarks

Will encode characters according to the UTF-8 character set.

Encode(String, Encoding)

Encodes the specified string.

Declaration
public static string Encode(string str, Encoding e)
Parameters
Type Name Description
System.String str

The string to encode.

System.Text.Encoding e

The encoding to use.

Returns
Type Description
System.String

An encoded string.

Encode(String, Encoding, Url.EncodeByte)

Encodes the specified string.

Declaration
public static string Encode(string str, Encoding e, Url.EncodeByte encodingRule)
Parameters
Type Name Description
System.String str

The string to encode.

System.Text.Encoding e

The encoding to use.

Url.EncodeByte encodingRule

The method used to determine if and how a character should be encoded.

Returns
Type Description
System.String

An encoded string.

Equals(Object)

Determines whether the specified System.Object is equal to the current System.Object.

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
System.Object obj

The System.Object to compare with the current System.Object.

Returns
Type Description
System.Boolean

true if the specified System.Object is equal to the current System.Object; otherwise, false.

Overrides
System.Object.Equals(System.Object)
Remarks

Will compare the Uri property to determine equality.

GetComponents(UriComponents, UriFormat)

Gets the specified components from the url (appended in returned string)

Declaration
public string GetComponents(UriComponents components, UriFormat format)
Parameters
Type Name Description
System.UriComponents components

The components to get

System.UriFormat format

The format of the Uri

Returns
Type Description
System.String

The components appended

GetHashCode()

Serves as a hash function for a particular type.

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32

A hash code for the current System.Object.

Overrides
System.Object.GetHashCode()

IsEmpty()

Determines whether this instance is empty or not.

Declaration
public bool IsEmpty()
Returns
Type Description
System.Boolean

true if this instance is empty; otherwise, false.

QueryEncodingRule(Byte)

The URL encoding rules for the query string.

Declaration
public static Url.EncodeAs QueryEncodingRule(byte b)
Parameters
Type Name Description
System.Byte b

The byte to encode.

Returns
Type Description
Url.EncodeAs

The encoded byte as a string.

SegmentEncodingRule(Byte)

The URL encoding rules for a URL segment.

Declaration
public static Url.EncodeAs SegmentEncodingRule(byte b)
Parameters
Type Name Description
System.Byte b

The byte to encode.

Returns
Type Description
Url.EncodeAs

The encoded byte as a string.

ToString()

Returns a canonical string representation for the specified Url instance.

Declaration
public override string ToString()
Returns
Type Description
System.String

A String instance that contains the unescaped canonical representation of the Uri instance. All characters are unescaped except #, ?, and %.

Overrides
System.Object.ToString()

Operators

Implicit(String to Url)

Performs an implicit conversion from System.String to Url.

Declaration
public static implicit operator Url(string url)
Parameters
Type Name Description
System.String url

The URL need to be converted.

Returns
Type Description
Url

An instance of Url which store the url parameter.

Implements

System.Xml.Serialization.IXmlSerializable

Extension Methods