public override string MapPath(string path) { string mappedPath = String.Empty; bool isClientScriptPath = false; if (path == null || path.Length == 0 || 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('/', Path.DirectorySeparatorChar); if (mappedPath.Length > 0 && mappedPath[mappedPath.Length - 1] == Path.DirectorySeparatorChar && !mappedPath.EndsWith(":" + Path.DirectorySeparatorChar, StringComparison.Ordinal)) { mappedPath = mappedPath.Substring(0, mappedPath.Length - 1); } return(mappedPath); }
public override String MapPath(String path) { String mappedPath = String.Empty; if (path == null || path.Length == 0 || 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)) { // 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("/")) { mappedPath = _host.PhysicalPath + path.Substring(1); } else { mappedPath = _host.PhysicalPath + path; } } mappedPath = mappedPath.Replace('/', '\\'); if (mappedPath.EndsWith("\\") && !mappedPath.EndsWith(":\\")) { mappedPath = mappedPath.Substring(0, mappedPath.Length - 1); } return(mappedPath); }