Try our conversational search powered by Generative AI!

Class UriSupport

Contains various support functionality for dealing with URIs.

Inheritance
System.Object
UriSupport
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer
Assembly: EPiServer.Cms.AspNet.dll
Version: 11.20.7
Syntax
public static class UriSupport

Fields

HttpLocalhostUri

The HTTP URI to the local machine.

Declaration
[Obsolete("This field will be removed in an upcoming version.")]
public static readonly Uri HttpLocalhostUri
Field Value
Type Description
System.Uri

Properties

InternalUIUrl

Gets the URL to the UI folder.

Declaration
public static Url InternalUIUrl { get; }
Property Value
Type Description
Url

The internal UI URL.

Remarks

Use this cached representation of the 'EPiServer.Configuration.Settings.UIUrl' since accessing the configuration settings is very slow, and here you get the benefit of the Url class as well.

InternalUtilUrl

Gets the URL to the Util folder.

Declaration
public static Url InternalUtilUrl { get; }
Property Value
Type Description
Url

The internal util URL.

Remarks

Use this cached representation of the 'EPiServer.Configuration.Settings.UtilUrl' since accessing the configuration settings is very slow, and here you get the benefit of the Url class as well.

SiteDefinitionResolver

SiteDefinition Resolver

Declaration
[Obsolete("This dependency property will be removed in an upcoming version.")]
public static ISiteDefinitionResolver SiteDefinitionResolver { get; set; }
Property Value
Type Description
ISiteDefinitionResolver

SiteUrl

Gets the site URL.

Declaration
[Obsolete("Use SiteDefinition.Current.SiteUrl")]
public static Uri SiteUrl { get; }
Property Value
Type Description
System.Uri

The site URL.

UIUrl

Gets the UI URL.

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

The UI URL.

UtilUrl

Gets the util URL.

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

The util URL.

Methods

AbsolutePathForSite(String, SiteDefinition)

Gets an absolute virtual path for the site given by siteDef from the passed in virtual path.

Declaration
public static string AbsolutePathForSite(string virtualPath, SiteDefinition siteDef)
Parameters
Type Name Description
System.String virtualPath

The virtual path.

SiteDefinition siteDef

The SiteDefinition.

Returns
Type Description
System.String
Remarks

If siteDef then SiteDefinition.Current is used.

AbsoluteUrlBySettings(String)

Get the absolute URL for the site by settings, including scheme, host and port

Declaration
public static string AbsoluteUrlBySettings(string path)
Parameters
Type Name Description
System.String path

The path, will be resolved if required.

Returns
Type Description
System.String

A fully qualified URI starting with scheme, based on Web.Config settings

AbsoluteUrlFromUIBySettings(String)

Get the absolute URL from UI by settings, including scheme, host and port

Declaration
public static string AbsoluteUrlFromUIBySettings(string path)
Parameters
Type Name Description
System.String path

The path, will be resolved from UI if required.

Returns
Type Description
System.String

A fully qualified URI starting with scheme, based on Web.Config settings

AbsoluteUrlFromUtilBySettings(String)

Get the absolute URL from UI by settings, including scheme, host and port

Declaration
public static string AbsoluteUrlFromUtilBySettings(string path)
Parameters
Type Name Description
System.String path

The path, will be resolved from Util if required.

Returns
Type Description
System.String

A fully qualified URI starting with scheme, based on Web.Config settings

AddLanguageSelection(String, String)

Adds an epslanguage parameter to the query string of a URL.

Declaration
[Obsolete("Use EPiServer.Web.UriUtil.AddLanguageSelection instead.")]
public static string AddLanguageSelection(string url, string languageCode)
Parameters
Type Name Description
System.String url

The URL to add the parameter to.

System.String languageCode

The langauage code.

Returns
Type Description
System.String

The resulting URL as a string.

AddQueryString(String, String, String)

Add query string parameter to given url

Declaration
[Obsolete("Use EPiServer.Web.UriUtil.AddQueryString instead.")]
public static string AddQueryString(string url, string name, string val)
Parameters
Type Name Description
System.String url

The original url (may include query string parameters)

System.String name

Name of the query string parameter (for example "status")

System.String val

The value of the query string parameter

Returns
Type Description
System.String

The new url with the query string added.

Remarks

This method will replace the value of an existing query string with the same name.

AddValuesToCollection(NameValueCollection, NameValueCollection)

Adds values to a NameValueCollection from another NameValueCollection.

Declaration
[Obsolete("Use NameValueCollection.Add method instead.")]
public static void AddValuesToCollection(NameValueCollection addTo, NameValueCollection addFrom)
Parameters
Type Name Description
System.Collections.Specialized.NameValueCollection addTo

The collection where the values will be added

System.Collections.Specialized.NameValueCollection addFrom

The collection that contains the values that will be added

AddValuesToCollection(NameValueCollection, NameValueCollection, List<String>, List<String>)

Adds values to a NameValueCollection from another NameValueCollection.

Declaration
[Obsolete("This method is no longer in use and will not be replaced.")]
public static void AddValuesToCollection(NameValueCollection addTo, NameValueCollection addFrom, List<string> includeKeys, List<string> excludeKeys)
Parameters
Type Name Description
System.Collections.Specialized.NameValueCollection addTo

The collection where the values will be added

System.Collections.Specialized.NameValueCollection addFrom

The collection that contains the values that will be added

System.Collections.Generic.List<System.String> includeKeys

List with the only keys that should be added. null = all keys in the addTo collection will be added

System.Collections.Generic.List<System.String> excludeKeys

List with the keys that not should be added. null = all keys in the addTo collection includeKeys will be added

Remarks

If includeKeys is null and lstDoNotAddKeys is null, all keys will be added If excludeKeys has keys and lstDoNotAddKeys has keys, all keys in includeKeys that is not contained in excludeKeys will be added

AppendQuerystring(Uri, Uri)

Append the query strings from two URIs.

Declaration
[Obsolete("This method is no longer in use and will not be replaced.")]
public static string AppendQuerystring(Uri firstUri, Uri secondUri)
Parameters
Type Name Description
System.Uri firstUri

The first URI.

System.Uri secondUri

The second URI.

Returns
Type Description
System.String

An appended query string without leading '?', but with appropriate URL-encoding

BuildQueryString(NameValueCollection)

Make a query string from a collection, no leading '?'

Declaration
[Obsolete("Use EPiServer.Web.UriUtil.BuildQueryString instead.")]
public static string BuildQueryString(NameValueCollection nvc)
Parameters
Type Name Description
System.Collections.Specialized.NameValueCollection nvc

The collection containing the query data.

Returns
Type Description
System.String

The query string with URL encoding, or an empty string (not null)

BuildQueryString(NameValueCollection, Encoding)

Builds a query string from a collection, no leading '?'

Declaration
[Obsolete("Use EPiServer.Web.UriUtil.BuildQueryString instead.")]
public static string BuildQueryString(NameValueCollection nvc, Encoding encoding)
Parameters
Type Name Description
System.Collections.Specialized.NameValueCollection nvc

The collection containing the query data.

System.Text.Encoding encoding

The encoding to use.

Returns
Type Description
System.String

The query string with URL encoding, or an empty string (not null)

BuildQueryStringQ(NameValueCollection)

Make a query string from a collection, with leading '?'

Declaration
[Obsolete("Call BuildQueryString and add the leading '?' manually instead.")]
public static string BuildQueryStringQ(NameValueCollection nvc)
Parameters
Type Name Description
System.Collections.Specialized.NameValueCollection nvc
Returns
Type Description
System.String

The query string with URL encoding and leading '?', or an empty string (not null)

BuildUrlWithPageReference(String, ContentReference)

Helper method to construct a URL with a content reference parameter

Declaration
[Obsolete("Call EPiServer.Web.UriUtil.AddQueryString with an 'id' key and content link value instead.")]
public static string BuildUrlWithPageReference(string url, ContentReference contentLink)
Parameters
Type Name Description
System.String url

The original URL

ContentReference contentLink

Content that should be referenced by the URL

Returns
Type Description
System.String

A new URL

Remarks

This method is primarily intended to be used with a URL read from the "PageURL" property of a PageData class. In some special cases you may need to retarget the URL to another page or another version of the same page.

Clear()

Resets cached values.

Declaration
[Obsolete("This method should not be needed externally and will removed.")]
public static void Clear()
Remarks

For performance reasons some configuration values are cached in the UriSupport class (UIUrl and UtilUrl). If the corresponding configuration values are updated without an application restart you should call this method to make sure that the new values are used.

Note: During normal circumstances you should never need to call this method.

Combine(String, String)

Combine two HTTP-scheme URLs or paths. Use for simple and robust concatentation of slash-separated paths, even if part of a full http: URL.

Declaration
[Obsolete("Use EPiServer.Web.UriUtil.Combine instead.")]
public static string Combine(string s1, string s2)
Parameters
Type Name Description
System.String s1

First part, may include scheme, host etc

System.String s2

Second part, may include traling query string, fragment etc

Returns
Type Description
System.String

The correctly combined paths regardless of if s1 ends or not, or s2 starts or not, with "/"

Combine(Uri, Uri)

Combines the specified site root with a URL that can be absolute or application relative.

Declaration
[Obsolete("This method is no longer in use and will not be replaced.")]
public static Uri Combine(Uri siteRoot, Uri absoluteOrSiteRootRelative)
Parameters
Type Name Description
System.Uri siteRoot

The site root.

System.Uri absoluteOrSiteRootRelative

The absolute or site root relative url.

Returns
Type Description
System.Uri

The combined Uri

CreateAbsoluteUri(Url)

Creates an absolute URI from a Url instance.

Declaration
public static Uri CreateAbsoluteUri(Url url)
Parameters
Type Name Description
Url url

The URL.

Returns
Type Description
System.Uri

An absolute System.Uri for the Url.

EscapeUriSegments(String)

Converts all characters, except RFC 2396 reserved except '?' and unreserved characters, to their hexadecimal representation. This is equivalent to escaping all but RFC 2396 pchar characters in an abs_path. Use this method to escape paths in URI's. All Unicode characters are converted to UTF-8 format before being escaped. There must be no escaped characters in the string.

Declaration
[Obsolete("Use EPiServer.Url.Encode with Encoding.UTF8 and SegmentEncodingRule instead.")]
public static string EscapeUriSegments(string s)
Parameters
Type Name Description
System.String s

The string to escape

Returns
Type Description
System.String

The encoded representation

Remarks

This method differs from Uri.EscapeUriString in that it also encodes '#', which although documented as doing, Uri.EscapeUriString does not. This is either a code-defect or a documentation issue in .NET framework 2.0. It also differs in that it encodes '?' and '&', wich Uri.EscapeUriString does not claim to do, nor does. Note that this method does not allow the use of '/' in the separate segments. Use System.Uri.UnescapeDataString to get the original string back.

GetSiteDefinition(UrlBuilder)

Determines whether the specified URL refers to any known configured enterprise sites, and returns the appropriate SiteDefinition if so.

Declaration
public static SiteDefinition GetSiteDefinition(UrlBuilder url)
Parameters
Type Name Description
UrlBuilder url
Returns
Type Description
SiteDefinition

IsDataUri(String)

Determines whether the provided URI string is a data URI, e.g. data:image;base64,ZWF0IG15IHNob3J0cyE=.

Declaration
[Obsolete("Use EPiServer.Web.UriUtil.IsDataUri instead.")]
public static bool IsDataUri(string uri)
Parameters
Type Name Description
System.String uri

The URI string to test.

Returns
Type Description
System.Boolean

True if the string follows a data URI pattern; otherwise false.

IsSchemeSpecified(String)

Checks if the provided string represents an absolute URI (begins with scheme)

Declaration
[Obsolete("Use EPiServer.Web.UriUtil.IsSchemeSpecified instead.")]
public static bool IsSchemeSpecified(string uri)
Parameters
Type Name Description
System.String uri

String representing the URI

Returns
Type Description
System.Boolean

IsSiteUrlByRequestOrSettings(String)

Determines whether an URL is local by comparing with current request or settings

Declaration
public static bool IsSiteUrlByRequestOrSettings(string url)
Parameters
Type Name Description
System.String url

The URL.

Returns
Type Description
System.Boolean

true if the specified URL is URL local by request or settings; otherwise, false.

IsSiteUrlByRequestOrSettings(Uri)

Determines whether an URL is local by comparing with current request or settings

Declaration
public static bool IsSiteUrlByRequestOrSettings(Uri url)
Parameters
Type Name Description
System.Uri url

The URL.

Returns
Type Description
System.Boolean

true if the specified URL is URL local by request or settings; otherwise, false.

IsStringWellFormedUri(String)

Uses System.Uri.IsWellFormedUriString(System.String,System.UriKind) but treat relative links as http based links.

Declaration
[Obsolete("Use EPiServer.Web.UriUtil.IsStringWellFormedUri instead.")]
public static bool IsStringWellFormedUri(string uriString)
Parameters
Type Name Description
System.String uriString

The string to check for Uri complience

Returns
Type Description
System.Boolean

true if string is considered a well formed Uri else false

RemoveQueryStringDelimeter(String)

Since the Framework can't decide on if to include the delimiter (?) or not, this little helper will remove it when necessary.

Declaration
[Obsolete("Trim any leading '?' manually instead.")]
public static string RemoveQueryStringDelimeter(string query)
Parameters
Type Name Description
System.String query

null, empty, or string with or without delimiter '?'

Returns
Type Description
System.String

null, empty or string without delimiter '?'

ResolveUrlBySettings(String)

Resolves the application relative path, using configuration settings.

Declaration
public static string ResolveUrlBySettings(string path)
Parameters
Type Name Description
System.String path

The path.

Returns
Type Description
System.String

A root-relative path

Remarks

Handles both relative and absolute URI's.

ResolveUrlFromUIAsRelativeOrAbsolute(String)

Resolves the URL from UI as relative or absolute.

Declaration
public static string ResolveUrlFromUIAsRelativeOrAbsolute(string path)
Parameters
Type Name Description
System.String path

The path.

Returns
Type Description
System.String

A string with the path resolved either as an absolute URL (with scheme, host etc) if the UIUrl is an absolute URL, or as a rooted, relative path (starting with /) if the UIUrl is not an absolute URL.

ResolveUrlFromUIBySettings(String)

Resolves the path relative the UI directory.

Declaration
public static string ResolveUrlFromUIBySettings(string path)
Parameters
Type Name Description
System.String path

The path.

Returns
Type Description
System.String

A root-relative path

ResolveUrlFromUtilBySettings(String)

Resolves the path relative the Util directory.

Declaration
public static string ResolveUrlFromUtilBySettings(string path)
Parameters
Type Name Description
System.String path

The path.

Returns
Type Description
System.String

A root-relative path

Split(String)

Splits the specified escaped URL into three parts: [0] - The [scheme][host][path] portion - before any fragment or query [1] - The query, if any, including the '?' [2] - The fragment, if any, including the '#'

Declaration
[Obsolete("Use EPiServer.Web.UriUtil.Split instead.")]
public static string[] Split(string url)
Parameters
Type Name Description
System.String url

The URL.

Returns
Type Description
System.String[]

A string[3] array with the parts, or empty strings if no such part

SplitNoDelim(String)

Splits the specified escaped URL into three parts: [0] - The [scheme][host][path] portion - before any fragment or query [1] - The query, if any, excluding the '?' [2] - The fragment, if any, excluding the '#'

Declaration
[Obsolete("Use EPiServer.Web.UriUtil.SplitNoDelim instead.")]
public static string[] SplitNoDelim(string url)
Parameters
Type Name Description
System.String url

The URL.

Returns
Type Description
System.String[]

A string[3] array with the parts, or empty strings if no such part