public string MakeRelative(HttpRequest request)
        {
            Uri    u = null;
            string s = request.RawUrl;

            try {
                u = new Uri(s);
            } catch (UriFormatException) {
                if ((s.StartsWith("/")) || (s.StartsWith("\\")))
                {
                    s = (RuntimePlatformUtils.RequestIsHttps(request) ? "https" : "http") + "://localhost" + s;
                }
                else
                {
                    s = (RuntimePlatformUtils.RequestIsHttps(request) ? "https" : "http") + "://localhost/" + s;
                }
                u = new Uri(s);
            }
            return(MakeRelative(u));
        }
        public void Parse(Uri uri)
        {
            _protocol = uri.Scheme;
            if (uri.Scheme == "http" && RuntimePlatformUtils.RequestIsHttps(HttpContext.Current.Request))
            {
                _protocol = "https";
            }
            _server      = uri.Host;
            _session     = "";
            _sessionless = true;
            _multitenant = false;
            _tenant      = "";
            _path        = "";
            _file        = "";
            if (!uri.IsDefaultPort)
            {
                _server += ":" + uri.Port.ToString();
            }
            int index = 1;

            _espace = CleanLastSlash(uri.Segments[index++]);
            if (uri.Segments.Length > 2)
            {
                if (uri.Segments[index].StartsWith(RuntimePlatformUtils.SessionPrefix))                    // #49674
                {
                    _session     = CleanLastSlash(uri.Segments[index++]);
                    _sessionless = false;
                }
                if (uri.Segments[index].IndexOf(".") < 0)
                {
                    _tenant = CleanLastSlash(uri.Segments[index++]);
                    if (_tenant == "img")
                    {
                        _path   = _tenant + "/";
                        _tenant = "";
                    }
                    else
                    {
                        _multitenant = true;
                    }
                }
                while ((index < uri.Segments.Length) && (uri.Segments[index].IndexOf(".") < 0))
                {
                    _path += uri.Segments[index++];
                }
                _path = CleanLastSlash(_path);

                if (index < uri.Segments.Length)
                {
                    _file = CleanLastSlash(uri.Segments[index++]);
                }
            }

            // Check that the img we earlier assumed to be from an image request lives
            // up to the hype.
            if (_path.StartsWith("img"))
            {
                // If a file wasn't request the "img" part this is a tenant default request
                // and not an image request.
                bool bImageReq = true;

                if (_file == String.Empty)
                {
                    bImageReq = false;
                }
                else
                {
                    int    pos = _file.LastIndexOf(".");
                    string ext = _file.Substring(pos, _file.Length - pos);
                    switch (ext.ToLower())
                    {
                    case ".gif":
                    case ".jpg":
                    case ".jpeg":
                    case ".png":
                    case ".bmp":
                    case ".wbmp": {
                        break;
                    }

                    default: {
                        bImageReq = false;
                        break;
                    }
                    }
                }

                if (!bImageReq)
                {
                    _tenant      = "img";
                    _multitenant = true;
                    _path        = _path.Substring(3, _path.Length - 3);
                    if (_path.StartsWith("/"))
                    {
                        _path = _path.Substring(1, _path.Length - 1);
                    }
                }
            }
            _query = uri.Query;
        }