Пример #1
0
        public override string MapPath(string path)
        {
            string mappedPath;
            bool   isClientScriptPath;

            if (String.IsNullOrEmpty(path) || path.Equals("/"))
            {
                // asking for the site root
                if (Host.VirtualPath == "/")
                {
                    // app at the site root
                    mappedPath = Host.PhysicalPath;
                }
                else
                {
                    // unknown site root - don't point to app root to avoid double config inclusion
                    mappedPath = Environment.SystemDirectory;
                }
            }
            else if (Host.IsVirtualPathAppPath(path))
            {
                // application path
                mappedPath = Host.PhysicalPath;
            }
            else if (Host.IsVirtualPathInApp(path, out isClientScriptPath))
            {
                if (isClientScriptPath)
                {
                    mappedPath = Host.PhysicalClientScriptPath + path.Substring(Host.NormalizedClientScriptPath.Length);
                }
                else
                {
                    // inside app but not the app path itself
                    mappedPath = Host.PhysicalPath + path.Substring(Host.NormalizedVirtualPath.Length);
                }
            }
            else
            {
                // outside of app -- make relative to app path
                if (path.StartsWith("/", StringComparison.Ordinal))
                {
                    mappedPath = Host.PhysicalPath + path.Substring(1);
                }
                else
                {
                    mappedPath = Host.PhysicalPath + path;
                }
            }

            mappedPath = mappedPath.Replace('/', '\\');

            if (mappedPath.EndsWith("\\", StringComparison.Ordinal) && !mappedPath.EndsWith(":\\", StringComparison.Ordinal))
            {
                mappedPath = mappedPath.Substring(0, mappedPath.Length - 1);
            }

            return(mappedPath);
        }