/// <summary>
        /// Returns the base URL of the HydroPortal.  This is required in order to properly construct REST queries on the portal.
        /// </summary>
        /// <param name="portalUrl">Original HydroPortal URL, e.g., https://hydroportal.crwr.utexas.edu/geoportal/catalog/main/home.page or https://hydroportal.crwr.utexas.edu/geoportal</param>
        /// <returns>Base HydroPortal URL, e.g., https://hydroportal.crwr.utexas.edu/geoportal</returns>
        private string GetBasePortalUrl(string portalUrl)
        {
            // Create a URI object from the given portal URL.  This accounts for possible redirect.
            Uri    uri     = WebOperations.GetUri(portalUrl, true);
            string baseUrl = uri.ToString();

            // Trim the home page fluff
            int index = baseUrl.ToLower().IndexOf("geoportal/catalog");

            if (index > -1)
            {
                baseUrl = portalUrl.Substring(0, index + 9);
            }

            // Trim current searches
            index = baseUrl.IndexOf("geoportal/rest");
            if (index > -1)
            {
                baseUrl = portalUrl.Substring(0, index + 9);
            }

            // Trim parameters
            index = baseUrl.IndexOf("?");
            if (index > -1)
            {
                baseUrl = portalUrl.Substring(0, index);
            }

            // Make sure this is still a valid URL
            if (!WebOperations.IsUrlValid(baseUrl, false))
            {
                baseUrl = uri.ToString();                  // Revert back to the URI that worked
            }

            // Remove trailing backslash
            index = baseUrl.LastIndexOf("/");
            if (index == (baseUrl.Length - 1))
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }

            return(baseUrl);
        }