Пример #1
0
        //
        // 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 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());
 }