Sage.UrlGenerator.GetUrl C# (CSharp) Method

GetUrl() public method

Resolves a link href based on the attributes of the specified linkElement.

The attributes on the element that will be taken into account:

Attribute Description id The id of the URL of the link to resolve:

<sage:link id="CustomerSuport" />

values To add formatting values to the resulting URL, such as the ID of the current customer, use the values attribute:

<sage:link id="CustomerSuport" values="id=${CustomerID}"/>

encode To URL-encode the resulting URL, use the encode attribute and set it's value to "1", "true", or "yes".
public GetUrl ( XmlElement linkElement ) : string
linkElement System.Xml.XmlElement The element that contains attributes that define the link to resolve.
return string
        public string GetUrl(XmlElement linkElement)
        {
            string linkName = this.Context.ProcessText(linkElement.GetAttribute("ref"));
            string linkValues = this.Context.ProcessText(linkElement.GetAttribute("values"));
            string linkHash = this.Context.ProcessText(linkElement.GetAttribute("hash"));
            bool urlEncode = linkElement.GetAttribute("encode").ContainsAnyOf("yes", "true", "1");
            bool qualify = linkElement.GetAttribute("absolute").ContainsAnyOf("yes", "true", "1");

            string linkHref = null;

            if (!string.IsNullOrEmpty(linkName))
            {
                linkHref = this.GetUrl(linkName, linkValues, linkHash, qualify);
                if (!string.IsNullOrWhiteSpace(linkHash))
                {
                    int hashIndex = linkHref.IndexOf("#", System.StringComparison.Ordinal);
                    if (hashIndex != -1)
                        linkHref = linkHref.Substring(0, hashIndex);

                    linkHref = string.Concat(linkHref, "#", linkHash.Trim('#'));
                }
            }

            if (urlEncode && !string.IsNullOrEmpty(linkHref))
                linkHref = HttpUtility.UrlEncode(linkHref);

            return linkHref;
        }

Same methods

UrlGenerator::GetUrl ( string linkName, NameValueCollection query = null, string hashString = null, bool qualify = false ) : string
UrlGenerator::GetUrl ( string linkName, string query, string hashString = null, bool qualify = false ) : string