Пример #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);
        }
Пример #2
0
        private bool TryParseRequest()
        {
            Reset();

            ReadAllHeaders();

            if (_headerBytes == null || _endHeadersOffset < 0 ||
                _headerByteStrings == null || _headerByteStrings.Count == 0)
            {
                Connection.WriteErrorAndClose(400);
                return(false);
            }

            ParseRequestLine();

            // Check for bad path
            if (IsBadPath())
            {
                Connection.WriteErrorAndClose(400);
                return(false);
            }

            bool clientScriptPath;

            // Check if the path is not well formed or is not for the current app
            if (!Host.IsVirtualPathInApp(Path, out clientScriptPath))
            {
                // HACK: Avoid out parameter!!!
                IsClientScriptPath = clientScriptPath;

                Connection.WriteErrorAndClose(404);
                return(false);
            }

            // HACK: Avoid out parameter!!!
            IsClientScriptPath = clientScriptPath;

            ParseHeaders();

            ParsePostedContent();

            return(true);
        }