Table of Contents

Class URLHelper

Namespace
CMS.Helpers
Assembly
CMS.Helpers.dll

URL processing methods.

public class URLHelper
Inheritance
object
URLHelper
Extension Methods

Fields

DEFAULT_HTTPS_PORT

Constant for HTTPS port.

public const int DEFAULT_HTTPS_PORT = 443

Field Value

int

DEFAULT_HTTP_PORT

Constant for HTTP port.

public const int DEFAULT_HTTP_PORT = 80

Field Value

int

SYSTEM_QUERY_PARAMETER

Used in system requests of live site pages, it prevents the system to log statistics or activities.

public const string SYSTEM_QUERY_PARAMETER = "systemrequest"

Field Value

string

Methods

AddQueryParameter(string, string, string)

Adds parameter to specified path.

public static string AddQueryParameter(string path, string parameterName, string parameterValue)

Parameters

path string

Path to be modified

parameterName string

Parameter name

parameterValue string

Parameter value

Returns

string

Remarks

This method does NOT support paths with anchor (#).

AppendQuery(string, string)

Appends the given query string to the path. If the path already contains query string, merges both.

public static string AppendQuery(string path, string newQuery)

Parameters

path string

Path

newQuery string

Query to append

Returns

string

ContainsProtocol(string)

Returns true if the URL contains the protocol part.

public static bool ContainsProtocol(string url)

Parameters

url string

URL to check

Returns

bool

EscapeSpecialCharacters(string)

Ensures URL without forbidden characters (%, &, #).

public static string EscapeSpecialCharacters(string url)

Parameters

url string

URL to replace special characters

Returns

string

ForbiddenCharactersReplacement()

Returns string containing replacement for forbidden characters (chars that can't be used in node alias and in the file system).

public static char ForbiddenCharactersReplacement()

Returns

char

GetDomain(string)

Returns domain or domain with port if present from specific URL.

public static string GetDomain(string url)

Parameters

url string

Input URL in format http(s)://domain

Returns

string

GetProtocol(string)

Returns protocol from url. e.g. http, https, ftp, ... If no protocol found, null is returned.

public static string GetProtocol(string url)

Parameters

url string

Url that may contain any protocol in valid format

Returns

string

GetQuery(string)

Gets the query from path.

public static string GetQuery(string path)

Parameters

path string

Path to process

Returns

string

GetSafeFileName(string, bool)

Returns the safe equivalent to the given file name.

public static string GetSafeFileName(string fileName, bool extensionIncluded = true)

Parameters

fileName string

Original file name

extensionIncluded bool

Indicates if given fileName contains extension.

Returns

string

GetSafeUrlPart(string, bool, bool, string)

Returns the safe part of URL. This method doesn't process complete URL it handles only part of URL.

public static string GetSafeUrlPart(string part, bool removeDiacritics = true, bool limitReplacements = true, string additionalAllowedCharacters = null)

Parameters

part string

String with URL part which may contain URL-unsafe characters. Enter only part of URL without any '/' characters

removeDiacritics bool

Indicates if diacritics should be removed from the URL part

limitReplacements bool

Indicates if replacements should be aggregated into single replacement character if found multiple invalid characters in row

additionalAllowedCharacters string

Additional allowed characters for the URL part

Returns

string

GetUrlParameter(string, string)

Returns value of query parameter from URL.

public static string GetUrlParameter(string url, string parameterName)

Parameters

url string

Input URL

parameterName string

Name of query parameter

Returns

string

RemoveAnchorFromUrl(string, out string)

Removes the anchor from the given url.

public static string RemoveAnchorFromUrl(string url, out string anchorValue)

Parameters

url string

The URL to be stripped.

anchorValue string

Returns the anchor value (including the anchor symbol).

Returns

string

The URL without the anchor.

RemovePathBase(string, string)

Removes the path base from given path.

public static string RemovePathBase(string path, string pathBase)

Parameters

path string

Path to process.

pathBase string

Path base to be removed.

Returns

string

RemovePort(string)

Removes the port part from the domain name.

[Obsolete("The member is deprecated and will be removed in the next version.")]
[ObsoleteSince(30, 0)]
public static string RemovePort(string domain)

Parameters

domain string

Domain name

Returns

string

RemoveProtocol(string)

Removes the protocol part from the URL.

public static string RemoveProtocol(string url)

Parameters

url string

URL to process (in format protocol://...)

Returns

string

RemoveQuery(string)

Removes the query from path.

public static string RemoveQuery(string path)

Parameters

path string

Path to process.

Returns

string

RemoveQueryParameter(string, string)

Removes specified parameters from the given path.

public static string RemoveQueryParameter(string path, string parameterName)

Parameters

path string

Path to be modified

parameterName string

Parameter name

Returns

string

RemoveWWW(string)

Trim www if input text starts with it.

[Obsolete("The member is deprecated and will be removed in the next version.")]
[ObsoleteSince(30, 0)]
public static string RemoveWWW(string inputText)

Parameters

inputText string

Returns

string

TrimReplacementCharacters(string)

Returns URL part without leading and trailing forbidden character replacements. Can be disabled by app key: CMSLimitUrlReplacement.

public static string TrimReplacementCharacters(string urlPart)

Parameters

urlPart string

String to be trimmed.

Returns

string

TryGetAbsoluteUrl(string, out Uri)

Gets the URI if provided string is URL in absolute format and has http or https scheme.

public static bool TryGetAbsoluteUrl(string url, out Uri uri)

Parameters

url string

URL string to check.

uri Uri

When this method returns true, contains the constructed System.Uri. Otherwise is null.

Returns

bool

Returns true if provided URL string is in absolute format and has http or https scheme; otherwise false.

TryGetQueryParameter(string, string, out string)

Gets the query string value for specified parameter name.

public static bool TryGetQueryParameter(string path, string parameterName, out string parameterValue)

Parameters

path string

Input path

parameterName string

Query string parameter name

parameterValue string

Value of the query parameter if found

Returns

bool

UnResolveUrl(string, string)

Un-resolves the given URL (replaces path base with ~).

public static string UnResolveUrl(string url, string pathBase)

Parameters

url string

URL to un-resolve

pathBase string

Path base

Returns

string