SetPathInfo() private method

private SetPathInfo ( string pi ) : void
pi string
return void
Esempio n. 1
0
        void RewritePath(string filePath, string pathInfo, string queryString, bool setClientFilePath)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }
            if (!VirtualPathUtility.IsValidVirtualPath(filePath))
            {
                throw new HttpException("'" + HttpUtility.HtmlEncode(filePath) + "' is not a valid virtual path.");
            }

            bool        pathRelative = VirtualPathUtility.IsAppRelative(filePath);
            bool        pathAbsolute = pathRelative ? false : VirtualPathUtility.IsAbsolute(filePath);
            HttpRequest req          = Request;

            if (req == null)
            {
                return;
            }

            if (pathRelative || pathAbsolute)
            {
                if (pathRelative)
                {
                    filePath = VirtualPathUtility.ToAbsolute(filePath);
                }
                else
                {
                    filePath = filePath;
                }
            }
            else
            {
                filePath = VirtualPathUtility.AppendTrailingSlash(req.BaseVirtualDir) + filePath;
            }

            if (!StrUtils.StartsWith(filePath, HttpRuntime.AppDomainAppVirtualPath))
            {
                throw new HttpException(404, "The virtual path '" + HttpUtility.HtmlEncode(filePath) + "' maps to another application.", filePath);
            }

            req.SetCurrentExePath(filePath);
            req.SetFilePath(filePath);

            if (setClientFilePath)
            {
                req.ClientFilePath = filePath;
            }

            // A null pathInfo or queryString is ignored and previous values remain untouched
            if (pathInfo != null)
            {
                req.SetPathInfo(pathInfo);
            }

            if (queryString != null)
            {
                req.QueryStringRaw = queryString;
            }
        }