Class URLHelper
URL processing methods.
public class URLHelper
- Inheritance
-
objectURLHelper
- 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
stringPath to be modified
parameterName
stringParameter name
parameterValue
stringParameter 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
stringPath
newQuery
stringQuery to append
Returns
- string
ContainsProtocol(string)
Returns true if the URL contains the protocol part.
public static bool ContainsProtocol(string url)
Parameters
url
stringURL to check
Returns
- bool
EscapeSpecialCharacters(string)
Ensures URL without forbidden characters (%, &, #).
public static string EscapeSpecialCharacters(string url)
Parameters
url
stringURL 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
stringInput 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
stringUrl 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
stringPath 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
stringOriginal file name
extensionIncluded
boolIndicates 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
stringString with URL part which may contain URL-unsafe characters. Enter only part of URL without any '/' characters
removeDiacritics
boolIndicates if diacritics should be removed from the URL part
limitReplacements
boolIndicates if replacements should be aggregated into single replacement character if found multiple invalid characters in row
additionalAllowedCharacters
stringAdditional 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
stringInput URL
parameterName
stringName 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
stringThe URL to be stripped.
anchorValue
stringReturns 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
stringPath to process.
pathBase
stringPath 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
stringDomain name
Returns
- string
RemoveProtocol(string)
Removes the protocol part from the URL.
public static string RemoveProtocol(string url)
Parameters
url
stringURL to process (in format protocol://...)
Returns
- string
RemoveQuery(string)
Removes the query from path.
public static string RemoveQuery(string path)
Parameters
path
stringPath to process.
Returns
- string
RemoveQueryParameter(string, string)
Removes specified parameters from the given path.
public static string RemoveQueryParameter(string path, string parameterName)
Parameters
path
stringPath to be modified
parameterName
stringParameter 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
stringString 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
stringURL string to check.
uri
UriWhen this method returns
true
, contains the constructed System.Uri. Otherwise isnull
.
Returns
- bool
Returns
true
if provided URL string is in absolute format and has http or https scheme; otherwisefalse
.
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
stringInput path
parameterName
stringQuery string parameter name
parameterValue
stringValue 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
stringURL to un-resolve
pathBase
stringPath base
Returns
- string