public static IEnumerable <KeyValuePair <string, string> > GetUrlComponents(string url, string returnQueryParameterName, bool returnPath, bool returnQuery, bool returnFile, bool returnHostPrefix, bool returnHostBase, bool returnHost) { var urlComponents = new UrlComponents(url); if (returnHost) { yield return(new KeyValuePair <string, string>("Host", urlComponents.Host)); } if (returnHostBase) { yield return(new KeyValuePair <string, string>("HostBase", urlComponents.HostBase)); } if (returnHostPrefix) { yield return(new KeyValuePair <string, string>("HostPrefix", urlComponents.HostPrefix)); } if (returnPath) { yield return(new KeyValuePair <string, string>("Path", urlComponents.Path)); } if (returnQuery) { yield return(new KeyValuePair <string, string>("Query", urlComponents.Query)); } if (returnFile) { yield return(new KeyValuePair <string, string>("File", urlComponents.File)); } if (returnQueryParameterName != null && urlComponents.QueryParameters != null && urlComponents.QueryParameters.Count > 0) { yield return(new KeyValuePair <string, string>("q:" + returnQueryParameterName, urlComponents.QueryParameters[returnQueryParameterName])); } }
public static string GetHost(string url, bool fastAndDirty) { if (!fastAndDirty) { var urlComponents = new UrlComponents(url); return(urlComponents.Host); } else { if (!string.IsNullOrEmpty(url)) { var splttedUrl = url.ToLowerInvariant().Split(UrlSlashDelimiter, StringSplitOptions.RemoveEmptyEntries); if (splttedUrl.Length > 0) { if (splttedUrl.Length >= 2) { return(splttedUrl[1]); } else { return(splttedUrl[0]); } } else { return(string.Empty); } } else { return(string.Empty); } } }
public static string GetQueryParameterValue(string url, string queryParameterName, string matchHostLowerCased) { var urlComponents = new UrlComponents(url); if (!string.IsNullOrEmpty(matchHostLowerCased)) { if (urlComponents.Host != matchHostLowerCased) { return(null); } else { return(urlComponents.QueryParameters[queryParameterName]); } } else { return(null); } }
public static IEnumerable<KeyValuePair<string, string>> GetUrlComponents(string url, string returnQueryParameterName, bool returnPath, bool returnQuery, bool returnFile, bool returnHostPrefix, bool returnHostBase, bool returnHost) { var urlComponents = new UrlComponents(url); if (returnHost) yield return new KeyValuePair<string, string>("Host", urlComponents.Host); if (returnHostBase) yield return new KeyValuePair<string, string>("HostBase", urlComponents.HostBase); if (returnHostPrefix) yield return new KeyValuePair<string, string>("HostPrefix", urlComponents.HostPrefix); if (returnPath) yield return new KeyValuePair<string, string>("Path", urlComponents.Path); if (returnQuery) yield return new KeyValuePair<string, string>("Query", urlComponents.Query); if (returnFile) yield return new KeyValuePair<string, string>("File", urlComponents.File); if (returnQueryParameterName != null && urlComponents.QueryParameters != null && urlComponents.QueryParameters.Count > 0) yield return new KeyValuePair<string, string>("q:" + returnQueryParameterName, urlComponents.QueryParameters[returnQueryParameterName]); }
public static string GetQueryParameterValue(string url, string queryParameterName, string matchHostLowerCased) { var urlComponents = new UrlComponents(url); if (!string.IsNullOrEmpty(matchHostLowerCased)) { if (urlComponents.Host != matchHostLowerCased) return null; else return urlComponents.QueryParameters[queryParameterName]; } else return null; }
public static string GetHost(string url, bool fastAndDirty) { if (!fastAndDirty) { var urlComponents = new UrlComponents(url); return urlComponents.Host; } else { if (!string.IsNullOrEmpty(url)) { var splttedUrl = url.ToLowerInvariant().Split(UrlSlashDelimiter, StringSplitOptions.RemoveEmptyEntries); if (splttedUrl.Length > 0) { if (splttedUrl.Length >= 2) return splttedUrl[1]; else return splttedUrl[0]; } else return string.Empty; } else return string.Empty; } }