Exemple #1
0
 /// <summary>
 ///     Returns the full path and query string of the specified URL (the part that follows the domain).</summary>
 /// <remarks>
 ///     This is intended to be used as <c>href</c> attribute values in <c>&lt;a&gt;</c> tags as it works well for an
 ///     absolute path within the same domain.</remarks>
 public static string ToHref(this IHttpUrl url)
 {
     var sb = new StringBuilder(128);
     for (int i = 0; i < url.ParentPaths.Length; i++)
         sb.Append(url.ParentPaths[i]);
     sb.Append(url.Path);
     url.AppendQueryString(sb, first: true);
     return sb.ToString();
 }
Exemple #2
0
 /// <summary>Returns the full and complete URL as a single string.</summary>
 public static string ToFull(this IHttpUrl url)
 {
     var sb = new StringBuilder(256);
     sb.Append(url.Https ? "https://" : "http://");
     sb.Append(url.Domain);
     if (url.ParentDomains != null)
         for (int i = url.ParentDomains.Length - 1; i >= 0; i--)
             sb.Append(url.ParentDomains[i]);
     if ((!url.Https && url.Port != 80) || (url.Https && url.Port != 443))
     {
         sb.Append(':');
         sb.Append(url.Port);
     }
     if (url.ParentPaths != null)
         for (int i = 0; i < url.ParentPaths.Length; i++)
             sb.Append(url.ParentPaths[i]);
     sb.Append(url.Path);
     url.AppendQueryString(sb, first: true);
     return sb.ToString();
 }
Exemple #3
0
 /// <summary>
 ///     Appends a key/value pair to the query string of a given Uri string.
 /// </summary>
 /// <param name="baseUri">Raw Uri string value to append to</param>
 /// <param name="key">Key to append</param>
 /// <param name="value">Value to append</param>
 /// <param name="urlEncode">Value indicating whether or not key and value need to be encoded</param>
 /// <returns>New Raw Uri value</returns>
 public static string AppendQueryString(this string baseUri, string key, string value, bool urlEncode = true)
 {
     return baseUri.AppendQueryString(new NameValueCollection { { key, value } }, urlEncode);
 }