void ParseParameterData() { string redirectUrl; string pathInfo = GetParameter("PATH_INFO"); string pathTranslated = GetParameter("PATH_TRANSLATED"); VPathToHost vapp; if (String.IsNullOrEmpty(pathTranslated) || String.IsNullOrEmpty(pathInfo) || pathInfo [0] != '/' || (null != (redirectUrl = GetParameter("REDIRECT_URL")) && redirectUrl.Length != 0 && pathInfo != redirectUrl)) { // Only consider REDIRECT_URL if it actually contains // something, since it may not always be present (depending // on installed Apache modules & setup). Also, never allow // PATH_INFO to be null (nor PATH_TRANSLATED), even for // cases where this method is mostly short-circuited. if (pathInfo == null) { SetParameter("PATH_INFO", String.Empty); } if (pathTranslated == null) { SetParameter("PATH_TRANSLATED", String.Empty); } vapp = WebServer.FastCgi.Server.GetApplicationForPath(HostName, PortNumber, Path, PhysicalPath); if (vapp == null) { Logger.Write(LogLevel.Debug, "Couldn't find vapp."); } else { ApplicationHost = vapp.AppHost as ApplicationHost; } return; } // At this point we have: (with REDIRECT_URL being optional) // // REDIRECT_URL=/dir/test.aspx/foo // PATH_INFO=/dir/test.aspx/foo // PATH_TRANSLATED=/srv/www/htdocs/dir/test.aspx/foo // SCRIPT_NAME=/cgi-bin/fastcgi-mono-server // SCRIPT_FILENAME=/srv/www/cgi-bin/fastcgi-mono-server string virtPath = pathInfo; string physPath = pathTranslated; string virtPathInfo = String.Empty; string physPathInfo = String.Empty; try { vapp = WebServer.FastCgi.Server.GetApplicationForPath( HostName, PortNumber, virtPath, physPath); if (vapp == null) { return; // Set values in finally } ApplicationHost = vapp.AppHost as ApplicationHost; if (ApplicationHost == null) { return; // Set values in finally } // Split the virtual path and virtual path-info string verb = GetParameter("REQUEST_METHOD"); if (String.IsNullOrEmpty(verb)) { verb = "GET"; // For the sake of paths, assume a default } ApplicationHost.GetPathsFromUri(verb, pathInfo, out virtPath, out virtPathInfo); if (virtPathInfo == null) { virtPathInfo = String.Empty; } if (virtPath == null) { virtPath = String.Empty; } // Re-map the physical path physPath = ApplicationHost.MapPath(virtPath) ?? String.Empty; // Re-map the physical path-info string relaPathInfo = virtPathInfo; if (relaPathInfo.Length != 0 && IOPath.DirectorySeparatorChar != '/') { relaPathInfo = relaPathInfo.Replace('/', IOPath.DirectorySeparatorChar); } while (relaPathInfo.Length > 0 && relaPathInfo[0] == IOPath.DirectorySeparatorChar) { relaPathInfo = relaPathInfo.Substring(1); } if (physPath.Length == 0) { physPathInfo = relaPathInfo; return; // Set values in finally } string physRoot = physPath; try { if (ApplicationHost.VirtualFileExists(virtPath)) { physRoot = IOPath.GetDirectoryName(physRoot) ?? String.Empty; } } catch { // Assume virtPath, physPath & physRoot // specify directories (and not files) } physPathInfo = IOPath.Combine(physRoot, relaPathInfo); } finally { // Now, if all went well, we set: // // SCRIPT_NAME=/dir/test.aspx // SCRIPT_FILENAME=/srv/www/htdocs/dir/test.aspx // PATH_INFO=/foo // PATH_TRANSLATED=/srv/www/htdocs/dir/foo SetParameter("SCRIPT_NAME", virtPath); SetParameter("SCRIPT_FILENAME", physPath); SetParameter("PATH_INFO", virtPathInfo); SetParameter("PATH_TRANSLATED", physPathInfo); } }