Exemple #1
0
        public VPathToHost GetApplicationForPath(string vhost, int port, string path,
                                                 bool defaultToRoot)
        {
            if (single_app)
            {
                return((VPathToHost)vpathToHost [0]);
            }

            VPathToHost bestMatch       = null;
            int         bestMatchLength = 0;

            for (int i = vpathToHost.Count - 1; i >= 0; i--)
            {
                VPathToHost v           = (VPathToHost)vpathToHost [i];
                int         matchLength = v.vpath.Length;
                if (matchLength <= bestMatchLength || !v.Match(vhost, port, path))
                {
                    continue;
                }

                bestMatchLength = matchLength;
                bestMatch       = v;
            }

            if (bestMatch != null)
            {
                lock (bestMatch) {
                    if (bestMatch.AppHost == null)
                    {
                        bestMatch.CreateHost(this, webSource);
                    }
                }
                return(bestMatch);
            }

            if (defaultToRoot)
            {
                return(GetApplicationForPath(vhost, port, "/", false));
            }

            if (verbose)
            {
                Console.WriteLine("No application defined for: {0}:{1}{2}", vhost, port, path);
            }

            return(null);
        }
        private VPathToHost GetApplicationForPath_existing(string vhost,
                                                           int vport,
                                                           string vpath)
        {
            VPathToHost bestMatch       = null;
            int         bestMatchLength = 0;

            // Checks for the matching vhost with the longest name.
            // For example, if the request is for
            // "/foo/bar/test.aspx", and hosts exist for "/", "/foo/",
            // "/foo/bar/", "/foo/bar/" should be used.
            for (int i = vpathToHost.Count - 1; i > -1; i--)
            {
                VPathToHost v           = (VPathToHost)vpathToHost [i];
                int         matchLength = v.vpath.Length;
                if (matchLength <= bestMatchLength ||
                    !v.Match(vhost, vport, vpath))
                {
                    continue;
                }

                bestMatchLength = matchLength;
                bestMatch       = v;
            }

            // Create the host and return the best match, if found.
            if (bestMatch != null)
            {
                CreateHost(bestMatch);
                return(bestMatch);
            }

            if (verbose)
            {
                Console.WriteLine(
                    "No application defined for: {0}:{1}{2}",
                    vhost, vport, vpath);
            }

            return(null);
        }