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

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

GetHttpDomain()

Returns the protocol and host of the current pageview

public static string GetHttpDomain()

Returns

string

I.e. http://www.dynamicweb.com

Exceptions

InvalidOperationException

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.

public static int GetInternalPageId(string url)

Parameters

url string

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

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 the current 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

URI used to do a url lookup

disablePortNumber bool

defines of port number should be appended

Returns

string

url with an optional port number

Exceptions

InvalidOperationException

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

public static bool IsLinkInternal(string url)

Parameters

url string

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

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

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, 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)

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