Table of Contents

Class LinkHelper

Namespace
Dynamicweb.Environment.Helpers
Assembly
Dynamicweb.Core.dll

Class LinkHelper is a utility for parsing and manipulating links.

public class LinkHelper
Inheritance
LinkHelper
Inherited Members

Methods

AddToQueryString(string)

Adds a parameter to the query string in the current request context and returns the combined result.

public static string AddToQueryString(string addThis)

Parameters

addThis string

The parameter and value to add to the query string. Example: ProductId=123.

Returns

string

The combined query string. Example: ?ID=12&ProductId=123

AddToQueryString(string, string)

Adds a parameter to the passed query string and returns the combined result.

public static string AddToQueryString(string queryString, string addThis)

Parameters

queryString string

The existing query string where the new part should be added. Ie. ?ID=12

addThis string

The parameter and vaulue to add to the querystring, i.e. Productid=123.

Returns

string

The combined querystring i.e ?ID=12&Productid=123

Remarks

AppendRemainingQueryWithoutId(string, IEnumerable<KeyValuePair<string, IEnumerable<string>>>)

Appends all remaining query parameters (excluding the parameter named 'id') to a base URL.

public static string AppendRemainingQueryWithoutId(string baseUrlString, IEnumerable<KeyValuePair<string, IEnumerable<string>>> queryParams)

Parameters

baseUrlString string

The base URL (without query string) to append to.

queryParams IEnumerable<KeyValuePair<string, IEnumerable<string>>>

A collection of query parameter key/value pairs where each key can have multiple values. Values that are null or empty strings are skipped.

Returns

string

The base URL unchanged if there are no remaining parameters, otherwise the base URL followed by '?' and the encoded query string.

GetHttpDomain()

Returns the base domain url, including the scheme, host and port (if port is non-default) of the current request url

public static string GetHttpDomain()

Returns

string

A domain url, e.g. https://www.dynamicweb.com

Exceptions

ContextUnavailableException

Thrown if this method is used in a scenario without a HttpContext

GetInternalPageId(string)

Extracts the internal Dynamicweb page ID from a given URL.

This method supports multiple internal URL formats used by Dynamicweb, such as:

  • "Default.aspx?ID=123"
  • "/default.aspx?id=123"
  • "default.asp?ID=123"
  • Just the numeric page ID itself, e.g. "123"

The method is case-insensitive and ignores extra query parameters or trailing fragments. Returns 0 if the URL is invalid or does not contain an internal ID.

public static int GetInternalPageId(string url)

Parameters

url string

The URL to analyze.

Returns

int

The internal page ID as an integer, or 0 if not found.

GetInternalPageIdsFromText(string)

Gets a collection of internal page IDs from the text.

public static List<int> GetInternalPageIdsFromText(string text)

Parameters

text string

The text with one or some internal links

Returns

List<int>

A collection of page IDs

GetInternalPageUrl(int?)

Gets a domain-relative url for the page with the given pageId. Format: Default.aspx?ID=pageId

public static string GetInternalPageUrl(int? 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.

public static int GetInternalParagraphId(string? url)

Parameters

url string

The 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

public static string GetInternalParagraphUrl(int pageId, int paragraphId)

Parameters

pageId int

The ID of the page to build the url.

paragraphId int

The 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 an absolute url with port number, if port number is different from the default port for the scheme.

public static string GetUrlWithPort(string uri, bool disablePortNumber)

Parameters

uri string

Relative or absolute URI

disablePortNumber bool

defines if port number should be omitted

Returns

string

Absolute url with an optional port number

Remarks

A relative url will be converted into an absolute url using the base domain url of the current request

Exceptions

ArgumentException

Thrown if uri cannot be parsed as a valid relative or absolute URI

ArgumentNullException

Thrown if uri is null

ContextUnavailableException

Thrown if this method is used in a scenario without a HttpContext

IsLinkInternal(string)

Determines whether a given URL points to an internal page in the current Dynamicweb site.

Internal links include:

  • Query links starting with '?', e.g. "?ID=123" "/Default.aspx?ID=123", "Default.aspx?AreaID=2"
  • Numeric URLs that represent page IDs directly, e.g. "123"

The check is case-insensitive and ignores fragment identifiers (#anchors).

public static bool IsLinkInternal(string url)

Parameters

url string

The URL to examine.

Returns

bool

True if the URL refers to a local page within the same Dynamicweb site; otherwise, false.

IsLinkInternalFile(string)

Determines whether the supplied link points to an internal file resource.

public static bool IsLinkInternalFile(string link)

Parameters

link string

The link string to evaluate (e.g. "/files/images/logo.png").

Returns

bool

true if the link starts with "/files/" (case-insensitive); otherwise false, including when link is null, empty, or whitespace.

Remarks

A link is considered an internal file link if it begins with the folder segment "/files/" (case-insensitive). The method does not check for file existence or validate the remaining path segments.

IsLinkInternalParagraph(string?)

Checks if an URL is an internal paragraph of the current website.

public static bool IsLinkInternalParagraph(string? url)

Parameters

url string

The 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

IsLinkInternalProductOrGroup(string)

Determines whether the supplied link string represents an internal Dynamicweb product or group link.

public static bool IsLinkInternalProductOrGroup(string link)

Parameters

link string

The link string to evaluate (e.g. "ProductID=123" or "GroupID=45").

Returns

bool

true if the link starts with "ProductID=" or "GroupID=" (case-insensitive); otherwise false, including when link is null, empty, or whitespace.

Remarks

A link is considered internal if it starts with either "ProductID=" or "GroupID=" (case-insensitive). The method does not validate the numeric value that may follow these prefixes; it only checks the prefix.

ParseQueryString(string)

public static NameValueCollection ParseQueryString(string query)

Parameters

query string

Returns

NameValueCollection

ReplaceQueryString(string, string)

Replaces a value for a given key in the query string in the current request context.

public static string ReplaceQueryString(string element, string newValue)

Parameters

element string

The element key to replace value on. Example: productid.

newValue string

The new value for the query string element key. Example: 567.

Returns

string

The new query string with the value replaced. Example: ?ID=12&ProductId=567

ReplaceQueryString(string, string, string)

Replaces a value for a given key in the passed query string.

public static string ReplaceQueryString(string queryString, string element, string newValue)

Parameters

queryString string

The query string, i.e. ?id=123&productid=234.

element string

The element key to replace value on, i.e. productid.

newValue string

The 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 string

Absolute path from url.

queryString string

The query string, i.e. ?id=123&productid=234.

element string

The element key to replace value on, i.e. productid.

newValue string

The 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.

public static string StripQueryString(string itemsToRemove)

Parameters

itemsToRemove string

The 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.

public static string StripQueryString(string queryString, string itemsToRemove)

Parameters

queryString string

The query string remove keys from, ie ?ID=123&productid=234&variantid=345.

itemsToRemove string

The 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 string

Absolute path from url.

queryString string

The query string remove keys from, ie ?ID=123&productid=234&variantid=345.

itemsToRemove string

The items to remove. i.e. ""productid,variantid"

Returns

string

The new querystring with the keys and their values removed i.e ?ID=12

To top