Sage.UrlGenerator.FormatAndRewriteUrl C# (CSharp) Method

FormatAndRewriteUrl() private method

Formats and rewrites the link pattern with the specified linkName.
Current configuration doesn't contain a link with name specified with /// .
private FormatAndRewriteUrl ( string linkName, NameValueCollection parameters, string hashString = null, bool qualify = false ) : string
linkName string Name of the link.
parameters System.Collections.Specialized.NameValueCollection The parameters.
hashString string The hash string.
qualify bool If set to true the resulting URL will be prefixed with .
return string
        internal string FormatAndRewriteUrl(string linkName, NameValueCollection parameters, string hashString = null, bool qualify = false)
        {
            if (!this.Links.ContainsKey(linkName))
            {
                log.ErrorFormat("The url configuration doesn't contain a url with name '{0}'", linkName);
                return string.Format("javascript:alert('Unresolved link: {0}')", linkName);
            }

            string linkPattern = this.Links[linkName].Value;

            QueryString formatValues = new QueryString { { "locale", context.Locale }, { "category", context.Category } };
            if (parameters != null)
                formatValues.Merge(parameters);

            string resultUrl = this.FormatPattern(linkPattern, formatValues);

            formatValues.Remove("locale");
            formatValues.Remove("category");

            string queryString = formatValues.ToString();
            if (queryString != string.Empty)
            {
                string join = resultUrl.Contains("?") ? "&" : "?";
                resultUrl = string.Concat(resultUrl, join, queryString);
            }

            if (!string.IsNullOrWhiteSpace(hashString))
            {
                string join = resultUrl.Contains("#") ? string.Empty : "#";
                resultUrl = string.Concat(resultUrl, join, hashString);
            }

            if (qualify)
                resultUrl = string.Concat(this.ServerPrefix, resultUrl);

            return resultUrl;
        }