Beispiel #1
0
        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]));
            }
        }
Beispiel #2
0
 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);
         }
     }
 }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
0
        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]);
        }
Beispiel #5
0
 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;
 }
Beispiel #6
0
 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;
     }
 }