// // Get CachedPathData for a virtual path. // The path may be supplied by user code, so check that it is valid. // static internal CachedPathData GetVirtualPathData(VirtualPath virtualPath, bool permitPathsOutsideApp) { if (!HostingEnvironment.IsHosted) { return(GetRootWebPathData()); } // Make sure it's not relative if (virtualPath != null) { virtualPath.FailIfRelativePath(); } // Check if the path is within the application. if (virtualPath == null || !virtualPath.IsWithinAppRoot) { if (permitPathsOutsideApp) { return(GetApplicationPathData()); } else { throw new ArgumentException(SR.GetString(SR.Cross_app_not_allowed, (virtualPath != null) ? virtualPath.VirtualPathString : "null")); } } // Construct a configPath based on the unvalidated virtualPath. string configPath = WebConfigurationHost.GetConfigPathFromSiteIDAndVPath(HostingEnvironment.SiteID, virtualPath); // Pass the virtualPath to GetConfigPathData to validate in the case where the // CachedPathData for the unsafeConfigPath is not found. return(GetConfigPathData(configPath)); }
public VirtualPath MakeRelative(VirtualPath toVirtualPath) { VirtualPath path = new VirtualPath(); this.FailIfRelativePath(); toVirtualPath.FailIfRelativePath(); path._virtualPath = UrlPath.MakeRelative(this.VirtualPathString, toVirtualPath.VirtualPathString); return(path); }
internal static VirtualPath Combine(VirtualPath v1, VirtualPath v2) { if (v1 == null) { v1 = HttpRuntime.AppDomainAppVirtualPathObject; } if (v1 == null) { v2.FailIfRelativePath(); return(v2); } return(v1.Combine(v2)); }
public VirtualPath MakeRelative(VirtualPath toVirtualPath) { VirtualPath resultVirtualPath = new VirtualPath(); // Neither path can be relative FailIfRelativePath(); toVirtualPath.FailIfRelativePath(); // Set it directly since we know the slashes are already ok resultVirtualPath._virtualPath = UrlPath.MakeRelative(this.VirtualPathString, toVirtualPath.VirtualPathString); #if DBG resultVirtualPath.ValidateState(); #endif return(resultVirtualPath); }
internal static VirtualPath Combine(VirtualPath v1, VirtualPath v2) { // If the first is null, use the app root instead if (v1 == null) { v1 = HttpRuntimePathUtil.AppDomainAppVirtualPathObject; } // If the first is still null, return the second, unless it's relative if (v1 == null) { v2.FailIfRelativePath(); return(v2); } return(v1.Combine(v2)); }
internal static CachedPathData GetVirtualPathData(VirtualPath virtualPath, bool permitPathsOutsideApp) { if (!HostingEnvironment.IsHosted) { return(GetRootWebPathData()); } if (virtualPath != null) { virtualPath.FailIfRelativePath(); } if ((virtualPath != null) && virtualPath.IsWithinAppRoot) { return(GetConfigPathData(WebConfigurationHost.GetConfigPathFromSiteIDAndVPath(HostingEnvironment.SiteID, virtualPath))); } if (!permitPathsOutsideApp) { throw new ArgumentException(System.Web.SR.GetString("Cross_app_not_allowed", new object[] { (virtualPath != null) ? virtualPath.VirtualPathString : "null" })); } return(GetApplicationPathData()); }
// // Get CachedPathData for a virtual path. // The path may be supplied by user code, so check that it is valid. // static internal CachedPathData GetVirtualPathData(VirtualPath virtualPath, bool permitPathsOutsideApp) { if (!HostingEnvironment.IsHosted) { return GetRootWebPathData(); } // Make sure it's not relative if (virtualPath != null) { virtualPath.FailIfRelativePath(); } // Check if the path is within the application. if (virtualPath == null || !virtualPath.IsWithinAppRoot) { if (permitPathsOutsideApp) { return GetApplicationPathData(); } else { throw new ArgumentException(SR.GetString(SR.Cross_app_not_allowed, (virtualPath != null) ? virtualPath.VirtualPathString : "null")); } } // Construct a configPath based on the unvalidated virtualPath. string configPath = WebConfigurationHost.GetConfigPathFromSiteIDAndVPath(HostingEnvironment.SiteID, virtualPath); // Pass the virtualPath to GetConfigPathData to validate in the case where the // CachedPathData for the unsafeConfigPath is not found. return GetConfigPathData(configPath); }
internal static VirtualPath Combine(VirtualPath v1, VirtualPath v2) { // If the first is null, use the app root instead if (v1 == null) { v1 = HttpRuntime.AppDomainAppVirtualPathObject; } // If the first is still null, return the second, unless it's relative if (v1 == null) { v2.FailIfRelativePath(); return v2; } return v1.Combine(v2); }
public VirtualPath MakeRelative(VirtualPath toVirtualPath) { VirtualPath resultVirtualPath = new VirtualPath(); // Neither path can be relative FailIfRelativePath(); toVirtualPath.FailIfRelativePath(); // Set it directly since we know the slashes are already ok resultVirtualPath._virtualPath = UrlPath.MakeRelative(this.VirtualPathString, toVirtualPath.VirtualPathString); #if DBG resultVirtualPath.ValidateState(); #endif return resultVirtualPath; }
private string MapPathActual(VirtualPath virtualPath, bool permitNull) { string result = null; Debug.Assert(virtualPath != null); virtualPath.FailIfRelativePath(); VirtualPath reqpath = virtualPath; if (String.CompareOrdinal(reqpath.VirtualPathString, _appVirtualPath.VirtualPathString) == 0) { // for application path don't need to call app host Debug.Trace("MapPath", reqpath +" is the app path"); result = _appPhysicalPath; } else { using (new ProcessImpersonationContext()) { // If there is a mapping for this virtual path in the call context, use it result = GetVirtualPathToFileMapping(reqpath); if (result == null) { // call host's mappath if (_configMapPath == null) { Debug.Trace("MapPath", "Missing _configMapPath"); throw new InvalidOperationException(SR.GetString(SR.Cannot_map_path, reqpath)); } Debug.Trace("MapPath", "call ConfigMapPath (" + reqpath + ")"); // see if the IConfigMapPath provider implements the interface // with VirtualPath try { if (null != _configMapPath2) { result = _configMapPath2.MapPath(GetSiteID(), reqpath); } else { result = _configMapPath.MapPath(GetSiteID(), reqpath.VirtualPathString); } if (HttpRuntime.IsMapPathRelaxed) result = HttpRuntime.GetRelaxedMapPathResult(result); } catch { if (HttpRuntime.IsMapPathRelaxed) result = HttpRuntime.GetRelaxedMapPathResult(null); else throw; } } } } if (String.IsNullOrEmpty(result)) { Debug.Trace("MapPath", "null Result"); if (!permitNull) { if (HttpRuntime.IsMapPathRelaxed) result = HttpRuntime.GetRelaxedMapPathResult(null); else throw new InvalidOperationException(SR.GetString(SR.Cannot_map_path, reqpath)); } } else { // ensure extra '\\' in the physical path if the virtual path had extra '/' // and the other way -- no extra '\\' in physical if virtual didn't have it. if (virtualPath.HasTrailingSlash) { if (!UrlPath.PathEndsWithExtraSlash(result) && !UrlPath.PathIsDriveRoot(result)) result = result + "\\"; } else { if (UrlPath.PathEndsWithExtraSlash(result) && !UrlPath.PathIsDriveRoot(result)) result = result.Substring(0, result.Length - 1); } Debug.Trace("MapPath", " result=" + result); } return result; }
private string MapPathActual(VirtualPath virtualPath, bool permitNull) { string originalResult = null; virtualPath.FailIfRelativePath(); VirtualPath path = virtualPath; if (string.CompareOrdinal(path.VirtualPathString, this._appVirtualPath.VirtualPathString) == 0) { originalResult = this._appPhysicalPath; } else { using (new ProcessImpersonationContext()) { originalResult = GetVirtualPathToFileMapping(path); if (originalResult == null) { if (this._configMapPath == null) { throw new InvalidOperationException(System.Web.SR.GetString("Cannot_map_path", new object[] { path })); } try { if (this._configMapPath2 != null) { originalResult = this._configMapPath2.MapPath(this.GetSiteID(), path); } else { originalResult = this._configMapPath.MapPath(this.GetSiteID(), path.VirtualPathString); } if (HttpRuntime.IsMapPathRelaxed) { originalResult = HttpRuntime.GetRelaxedMapPathResult(originalResult); } } catch { if (!HttpRuntime.IsMapPathRelaxed) { throw; } originalResult = HttpRuntime.GetRelaxedMapPathResult(null); } } } } if (string.IsNullOrEmpty(originalResult)) { if (permitNull) { return originalResult; } if (!HttpRuntime.IsMapPathRelaxed) { throw new InvalidOperationException(System.Web.SR.GetString("Cannot_map_path", new object[] { path })); } return HttpRuntime.GetRelaxedMapPathResult(null); } if (virtualPath.HasTrailingSlash) { if (!UrlPath.PathEndsWithExtraSlash(originalResult) && !UrlPath.PathIsDriveRoot(originalResult)) { originalResult = originalResult + @"\"; } return originalResult; } if (UrlPath.PathEndsWithExtraSlash(originalResult) && !UrlPath.PathIsDriveRoot(originalResult)) { originalResult = originalResult.Substring(0, originalResult.Length - 1); } return originalResult; }
internal static CachedPathData GetVirtualPathData(VirtualPath virtualPath, bool permitPathsOutsideApp) { if (!HostingEnvironment.IsHosted) { return GetRootWebPathData(); } if (virtualPath != null) { virtualPath.FailIfRelativePath(); } if ((virtualPath != null) && virtualPath.IsWithinAppRoot) { return GetConfigPathData(WebConfigurationHost.GetConfigPathFromSiteIDAndVPath(HostingEnvironment.SiteID, virtualPath)); } if (!permitPathsOutsideApp) { throw new ArgumentException(System.Web.SR.GetString("Cross_app_not_allowed", new object[] { (virtualPath != null) ? virtualPath.VirtualPathString : "null" })); } return GetApplicationPathData(); }