public override string MapPath(string path)
        {
            string eventResult = DoMapPathEvent(path);

            if (eventResult != null)
            {
                return(eventResult);
            }

            if (path == null || path.Length == 0 || path == HostVPath)
            {
                return(HostPath.Replace('/', Path.DirectorySeparatorChar));
            }

            if (path [0] == '~' && path.Length > 2 && path [1] == '/')
            {
                path = path.Substring(1);
            }

            int len = HostVPath.Length;

            if (path.StartsWith(HostVPath) && (path.Length == len || path [len] == '/'))
            {
                path = path.Substring(len + 1);
            }

            if (path.Length > 0 && path [0] == '/')
            {
                path = path.Substring(1);
            }

            return(Path.Combine(HostPath, path.Replace('/', Path.DirectorySeparatorChar)));
        }
Esempio n. 2
0
        // The logic here is as follows:
        //
        // If path is equal to the host's virtual path (including trailing slash),
        // return the host virtual path.
        //
        // If path is absolute (starts with '/') then check if it's under our host vpath. If
        // it is, base the mapping under the virtual application's physical path. If it
        // isn't use the physical root of the application server to return the mapped
        // path. If you have just one application configured, then the values computed in
        // both of the above cases will be the same. If you have several applications
        // configured for this xsp/mod-mono-server instance, then virtual paths outside our
        // application virtual path will return physical paths relative to the server's
        // physical root, not application's. This is consistent with the way IIS worker
        // request works. See bug #575600
        //
        public override string MapPath(string path)
        {
            string eventResult = DoMapPathEvent(path);

            if (eventResult != null)
            {
                return(eventResult);
            }

            string hostVPath    = HostVPath;
            int    hostVPathLen = HostVPath.Length;
            int    pathLen      = path != null ? path.Length : 0;
            bool   inThisApp    = path.StartsWith(hostVPath, StringComparison.Ordinal);

            if (pathLen == 0 || (inThisApp && (pathLen == hostVPathLen || (pathLen == hostVPathLen + 1 && path [pathLen - 1] == '/'))))
            {
                if (needToReplacePathSeparator)
                {
                    return(HostPath.Replace('/', pathSeparatorChar));
                }
                return(HostPath);
            }

            string basePath = null;

            switch (path [0])
            {
            case '~':
                if (path.Length >= 2 && path [1] == '/')
                {
                    path = path.Substring(1);
                }
                break;

            case '/':
                if (!inThisApp)
                {
                    basePath = HostPhysicalRoot;
                }
                break;
            }

            if (basePath == null)
            {
                basePath = HostPath;
            }

            if (inThisApp && (path.Length == hostVPathLen || path [hostVPathLen] == '/'))
            {
                path = path.Substring(hostVPathLen + 1);
            }

            path = path.TrimStart(mapPathTrimStartChars);
            if (needToReplacePathSeparator)
            {
                path = path.Replace('/', pathSeparatorChar);
            }

            return(Path.Combine(basePath, path));
        }