Example #1
0
        protected void SetUri(Uri baseAddress, string relativeAddress)
        {
            Uri fullUri = baseAddress;

            // Ensure that baseAddress Path does end with a slash if we have a relative address
            if (relativeAddress != string.Empty)
            {
                if (!baseAddress.AbsolutePath.EndsWith("/", StringComparison.Ordinal))
                {
                    UriBuilder uriBuilder = new UriBuilder(baseAddress);
                    TcpChannelListener.FixIpv6Hostname(uriBuilder, baseAddress);
                    uriBuilder.Path = uriBuilder.Path + "/";
                    baseAddress     = uriBuilder.Uri;
                }

                fullUri = new Uri(baseAddress, relativeAddress);

                // now see if we need to update our base address (for cases like relative path = "/foo")
                if (!baseAddress.IsBaseOf(fullUri))
                {
                    baseAddress = fullUri;
                }
            }

            baseUri = baseAddress;
            ValidateUri(fullUri);
            uri = fullUri;
        }
        public static Uri GetListenUri(Uri baseAddress, string relativeAddress)
        {
            Uri fullUri = baseAddress;

            // Ensure that baseAddress Path does end with a slash if we have a relative address
            if (!String.IsNullOrEmpty(relativeAddress))
            {
                if (!baseAddress.AbsolutePath.EndsWith("/", StringComparison.Ordinal))
                {
                    UriBuilder uriBuilder = new UriBuilder(baseAddress);
                    TcpChannelListener.FixIpv6Hostname(uriBuilder, baseAddress);
                    uriBuilder.Path = uriBuilder.Path + "/";
                    baseAddress     = uriBuilder.Uri;
                }

                fullUri = new Uri(baseAddress, relativeAddress);
            }

            return(fullUri);
        }
Example #3
0
        static Uri AddSegment(Uri baseUri, Uri fullUri)
        {
            Uri result = null;

            if (baseUri.AbsolutePath.Length < fullUri.AbsolutePath.Length)
            {
                UriBuilder builder = new UriBuilder(baseUri);
                TcpChannelListener.FixIpv6Hostname(builder, baseUri);
                if (!builder.Path.EndsWith("/", StringComparison.Ordinal))
                {
                    builder.Path = builder.Path + "/";
                    baseUri      = builder.Uri;
                }
                Uri    relativeUri  = baseUri.MakeRelativeUri(fullUri);
                string relativePath = relativeUri.OriginalString;
                int    slashIndex   = relativePath.IndexOf('/');
                string segment      = (slashIndex == -1) ? relativePath : relativePath.Substring(0, slashIndex);
                builder.Path = builder.Path + segment;
                result       = builder.Uri;
            }
            return(result);
        }