Class LinkHelper
- Namespace
- Dynamicweb.Environment.Helpers
- Assembly
- Dynamicweb.Core.dll
Class LinkHelper is a utility for parsing and manipulating links.
- Inheritance
-
Link
Helper
- Inherited Members
Methods
AddToQueryString(string)
Adds a parameter to the query string in the current request context and returns the combined result.
Parameters
addThis
stringThe parameter and vaulue to add to the querystring, i.e. Productid=123.
Returns
- string
The combined querystring i.e ?ID=12&Productid=123
AddToQueryString(string, string)
Adds a parameter to the passed query string and returns the combined result.
Parameters
queryString
stringThe existing query string where the new part should be added. Ie. ?ID=12
addThis
stringThe parameter and vaulue to add to the querystring, i.e. Productid=123.
Returns
- string
The combined querystring i.e ?ID=12&Productid=123
Remarks
http://cc.davelozinski.com/c-sharp/c-fastest-way-to-check-last-character-of-a-string https://theburningmonk.com/2012/05/performance-test-string-contains-vs-string-indexof-vs-regex-ismatch/
GetHttpDomain()
Returns the protocol and host of the current pageview
Returns
Exceptions
- Invalid
Operation Exception Thrown if this method is used in a scenario without a HttpContext
GetInternalPageId(string)
Returns the internal ID of the page in the specified URL.
Parameters
url
stringThe URL to parse, i.e. "Default.aspx?ID=123".
Returns
- int
System.Int32. The ID (123) from the querstring of the url "Default.aspx?ID=123"
Remarks
Returns 0 if an invalid url is passed, i.e. www.google.com
GetInternalPageIdsFromText(string)
Gets a collection of internal page IDs from the text.
Parameters
text
stringThe text with one or some internal links
Returns
GetInternalPageUrl(int?)
Gets a domain-relative url for the page with the given pageId
.
Format: Default.aspx?ID=pageId
Parameters
pageId
int?The ID of the page to get the url for.
Returns
- string
A string representing a url for a page with the given ID.
Remarks
The pageId
is not validated for whether the page exists.
GetInternalParagraphId(string?)
Returns the internal ID of the paragraph in the specified URL.
Parameters
url
stringThe URL to parse, i.e. "Default.aspx?ID=123#456".
Returns
- int
The paragraph ID (456) from the
url
.
GetInternalParagraphUrl(int, int)
Gets a domain-relative url for the paragraph with the given pageId
and paragraphId
.
Format: Default.aspx?ID=pageId
#paragraphId
Parameters
pageId
intThe ID of the page to build the url.
paragraphId
intThe ID of the paragraph to build the url.
Returns
- string
A string representing a url for a paragraph with the given IDs.
Remarks
The pageId
and paragraphId
are not validated for whether the page exists.
GetUrlWithPort(string, bool)
Gets the current url with port number, if port number is different from the default port for the scheme.
Parameters
uri
stringURI used to do a url lookup
disablePortNumber
booldefines of port number should be appended
Returns
- string
url with an optional port number
Exceptions
- Invalid
Operation Exception Thrown if this method is used in a scenario without a HttpContext
IsLinkInternal(string)
Checks if an URL is an internal page of the current website
Parameters
url
stringURL to be checked.
Returns
- bool
Returns true if the URL is a page of the current website, i.e. Default.aspx?ID=123
IsLinkInternalParagraph(string?)
Checks if an URL is an internal paragraph of the current website.
Parameters
url
stringThe URL to be checked.
Returns
- bool
Returns
true
if the URL is a paragraph of the current website, i.e. Default.aspx?ID=123#456
ParseQueryString(string)
Parameters
query
string
Returns
ReplaceQueryString(string, string)
Replaces a value for a given key in the query string in the current request context.
Parameters
element
stringThe element key to replace value on, i.e. productid.
newValue
stringThe new value for the querystring element key, i.e. 567.
Returns
- string
The new querystring with the value replaced i.e ?ID=12&Productid=567
ReplaceQueryString(string, string, string)
Replaces a value for a given key in the passed query string.
Parameters
queryString
stringThe query string, i.e. ?id=123&productid=234.
element
stringThe element key to replace value on, i.e. productid.
newValue
stringThe new value for the querystring element key, i.e. 567.
Returns
- string
The new querystring with the value replaced i.e ?ID=12&Productid=567
ReplaceQueryString(string, string, string, string)
Replaces a value for a given key in the passed query string.
public static string ReplaceQueryString(string urlAbsolutePath, string queryString, string element, string newValue)
Parameters
urlAbsolutePath
stringAbsolute path from url.
queryString
stringThe query string, i.e. ?id=123&productid=234.
element
stringThe element key to replace value on, i.e. productid.
newValue
stringThe new value for the querystring element key, i.e. 567.
Returns
- string
The new querystring with the value replaced i.e ?ID=12&Productid=567
StripQueryString(string)
Strips keys and their values from the query string in the current request context.
Parameters
itemsToRemove
stringThe items to remove. i.e. ""productid,variantid"
Returns
- string
The new querystring with the keys and their values removed i.e ?ID=12
StripQueryString(string, string)
Strips keys and their values from the query string.
Parameters
queryString
stringThe query string remove keys from, ie ?ID=123&productid=234&variantid=345.
itemsToRemove
stringThe items to remove. i.e. ""productid,variantid"
Returns
- string
The new querystring with the keys and their values removed i.e ?ID=12
StripQueryString(string, string, string)
Strips keys and their values from the query string.
public static string StripQueryString(string urlAbsolutePath, string queryString, string itemsToRemove)
Parameters
urlAbsolutePath
stringAbsolute path from url.
queryString
stringThe query string remove keys from, ie ?ID=123&productid=234&variantid=345.
itemsToRemove
stringThe items to remove. i.e. ""productid,variantid"
Returns
- string
The new querystring with the keys and their values removed i.e ?ID=12