Class URLHelper
URL processing methods.
public class URLHelper
- Inheritance
-
objectURLHelper
- Extension Methods
Constructors
URLHelper()
public URLHelper()
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
pathstringPath to be modified
parameterNamestringParameter name
parameterValuestringParameter 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
pathstringPath
newQuerystringQuery to append
Returns
- string
ContainsProtocol(string)
Returns true if the URL contains the protocol part.
public static bool ContainsProtocol(string url)
Parameters
urlstringURL to check
Returns
- bool
EscapeSpecialCharacters(string)
Ensures URL without forbidden characters (%, &, #).
public static string EscapeSpecialCharacters(string url)
Parameters
urlstringURL 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
urlstringInput 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
urlstringUrl that may contain any protocol in valid format
Returns
- string
GetQuery(string)
Gets the query from path.
public static string GetQuery(string path)
Parameters
pathstringPath 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
fileNamestringOriginal file name
extensionIncludedboolIndicates 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
partstringString with URL part which may contain URL-unsafe characters. Enter only part of URL without any '/' characters
removeDiacriticsboolIndicates if diacritics should be removed from the URL part
limitReplacementsboolIndicates if replacements should be aggregated into single replacement character if found multiple invalid characters in row
additionalAllowedCharactersstringAdditional 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
urlstringInput URL
parameterNamestringName 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
urlstringThe URL to be stripped.
anchorValuestringReturns 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
pathstringPath to process.
pathBasestringPath 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.")]
public static string RemovePort(string domain)
Parameters
domainstringDomain name
Returns
- string
RemoveProtocol(string)
Removes the protocol part from the URL.
public static string RemoveProtocol(string url)
Parameters
urlstringURL to process (in format protocol://...)
Returns
- string
RemoveQuery(string)
Removes the query from path.
public static string RemoveQuery(string path)
Parameters
pathstringPath to process.
Returns
- string
RemoveQueryParameter(string, string)
Removes specified parameters from the given path.
public static string RemoveQueryParameter(string path, string parameterName)
Parameters
pathstringPath to be modified
parameterNamestringParameter 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.")]
public static string RemoveWWW(string inputText)
Parameters
inputTextstring
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
urlPartstringString 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
urlstringURL string to check.
uriUriWhen this method returns
true, contains the constructed System.Uri. Otherwise isnull.
Returns
- bool
Returns
trueif 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
pathstringInput path
parameterNamestringQuery string parameter name
parameterValuestringValue 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
urlstringURL to un-resolve
pathBasestringPath base
Returns
- string