Пример #1
0
        // Override to qualify non-local image and link urls
        public virtual string OnQualifyUrl(string url)
        {
            var q = QualifyUrl?.Invoke(url);

            if (q != null)
            {
                return(url);
            }

            // Quit if we don't have a base location
            if (string.IsNullOrEmpty(UrlBaseLocation))
            {
                return(url);
            }

            // Is the url a fragment?
            if (url.StartsWith("#"))
            {
                return(url);
            }

            // Is the url already fully qualified?
            if (Utils.IsUrlFullyQualified(url))
            {
                return(url);
            }

            if (url.StartsWith("/"))
            {
                if (!string.IsNullOrEmpty(UrlRootLocation))
                {
                    return(UrlRootLocation + url);
                }

                // Need to find domain root
                var pos = UrlBaseLocation.IndexOf("://", StringComparison.Ordinal);
                if (pos == -1)
                {
                    pos = 0;
                }
                else
                {
                    pos += 3;
                }

                // Find the first slash after the protocol separator
                pos = UrlBaseLocation.IndexOf('/', pos);

                // Get the domain name
                var strDomain = pos < 0 ? UrlBaseLocation : UrlBaseLocation.Substring(0, pos);

                // Join em
                return(strDomain + url);
            }
            if (!UrlBaseLocation.EndsWith("/"))
            {
                return(UrlBaseLocation + "/" + url);
            }
            return(UrlBaseLocation + url);
        }
Пример #2
0
		// Override to qualify non-local image and link urls
		public virtual string OnQualifyUrl(string url)
		{
			if (QualifyUrl != null)
			{
				var q = QualifyUrl(url);
				if (q != null)
					return q;
			}

			// Quit if we don't have a base location
			if (String.IsNullOrEmpty(UrlBaseLocation))
				return url;

            // Is the url a fragment?
            if (url.StartsWith("#"))
                return url;

			// Is the url already fully qualified?
			if (Utils.IsUrlFullyQualified(url))
				return url;

			if (url.StartsWith("/"))
			{
				if (!string.IsNullOrEmpty(UrlRootLocation))
				{
					return UrlRootLocation + url;
				}

				// Need to find domain root
				int pos = UrlBaseLocation.IndexOf("://");
				if (pos == -1)
					pos = 0;
				else
					pos += 3;

				// Find the first slash after the protocol separator
				pos = UrlBaseLocation.IndexOf('/', pos);

				// Get the domain name
				string strDomain=pos<0 ? UrlBaseLocation : UrlBaseLocation.Substring(0, pos);

				// Join em
				return strDomain + url;
			}
			else
			{
				if (!UrlBaseLocation.EndsWith("/"))
					return UrlBaseLocation + "/" + url;
				else
					return UrlBaseLocation + url;
			}
		}
        public override string OnQualifyUrl(string url)
        {
            if (QualifyUrl != null)
            {
                var q = QualifyUrl(url);
                if (q != null)
                {
                    return(q);
                }
            }

            // Is the url a fragment?
            if (url.StartsWith("#"))
            {
                return(url);
            }

            // Is the url already fully qualified?
            if (url.Contains("://") || url.StartsWith("mailto:"))
            {
                return(url);
            }

            if (url.StartsWith("/"))
            {
                if (!string.IsNullOrEmpty(UrlRootLocation))
                {
                    return(UrlRootLocation + url);
                }

                // Quit if we don't have a base location
                if (string.IsNullOrEmpty(UrlBaseLocation))
                {
                    return(url);
                }

                // Need to find domain root
                int pos = UrlBaseLocation.IndexOf("://");
                if (pos == -1)
                {
                    pos = 0;
                }
                else
                {
                    pos += 3;
                }

                // Find the first slash after the protocol separator
                pos = UrlBaseLocation.IndexOf('/', pos);

                // Get the domain name
                string strDomain = pos < 0 ? UrlBaseLocation : UrlBaseLocation.Substring(0, pos);

                // Join em
                return(strDomain + url);
            }
            else
            {
                // Quit if we don't have a base location
                if (string.IsNullOrEmpty(UrlBaseLocation))
                {
                    return(url);
                }

                if (!UrlBaseLocation.EndsWith("/"))
                {
                    return(UrlBaseLocation + "/" + url);
                }
                else
                {
                    return(UrlBaseLocation + url);
                }
            }
        }