Beispiel #1
0
        internal void DoRuntimeValidation()
        {
            string directoryName = this.DirectoryName;

            if (!BuildManager.IsPrecompiledApp)
            {
                FindFileData data;
                if (!Util.IsValidFileName(directoryName))
                {
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Invalid_CodeSubDirectory", new object[] { directoryName }), base.ElementInformation.Properties["directoryName"].Source, base.ElementInformation.Properties["directoryName"].LineNumber);
                }
                VirtualPath virtualDir = HttpRuntime.CodeDirectoryVirtualPath.SimpleCombineWithDir(directoryName);
                if (!VirtualPathProvider.DirectoryExistsNoThrow(virtualDir))
                {
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Invalid_CodeSubDirectory_Not_Exist", new object[] { virtualDir }), base.ElementInformation.Properties["directoryName"].Source, base.ElementInformation.Properties["directoryName"].LineNumber);
                }
                FindFileData.FindFile(virtualDir.MapPathInternal(), out data);
                if (!System.Web.Util.StringUtil.EqualsIgnoreCase(directoryName, data.FileNameLong))
                {
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Invalid_CodeSubDirectory", new object[] { directoryName }), base.ElementInformation.Properties["directoryName"].Source, base.ElementInformation.Properties["directoryName"].LineNumber);
                }
                if (BuildManager.IsReservedAssemblyName(directoryName))
                {
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Reserved_AssemblyName", new object[] { directoryName }), base.ElementInformation.Properties["directoryName"].Source, base.ElementInformation.Properties["directoryName"].LineNumber);
                }
            }
        }
Beispiel #2
0
        internal static string GetDirectoryHash(VirtualPath virtualDir)
        {
            HashCodeCombiner hashCodeCombiner = new HashCodeCombiner();

            hashCodeCombiner.AddDirectory(virtualDir.MapPathInternal());
            return(hashCodeCombiner.CombinedHashString);
        }
Beispiel #3
0
        internal static bool VirtualFileExistsWithAssert(VirtualPath virtualPath)
        {
            string path = virtualPath.MapPathInternal();

            if (path != null)
            {
                InternalSecurityPermissions.PathDiscovery(path).Assert();
            }
            return(virtualPath.FileExists());
        }
        internal override string ComputeSourceDependenciesHashCode(VirtualPath virtualPath)
        {
            if (virtualPath == null)
            {
                virtualPath = base.VirtualPath;
            }
            HashCodeCombiner combiner = new HashCodeCombiner();

            combiner.AddResourcesDirectory(virtualPath.MapPathInternal());
            return(combiner.CombinedHashString);
        }
Beispiel #5
0
        // Validate the element for runtime use
        internal void DoRuntimeValidation()
        {
            string directoryName = DirectoryName;

            // If the app is precompiled, don't attempt further validation, sine the directory
            // will not actually exist (VSWhidbey 394333)
            if (BuildManager.IsPrecompiledApp)
            {
                return;
            }

            // Make sure it's just a valid simple directory name
            if (!Util.IsValidFileName(directoryName))
            {
                throw new ConfigurationErrorsException(
                          SR.GetString(SR.Invalid_CodeSubDirectory, directoryName),
                          ElementInformation.Properties[dirNameAttribName].Source, ElementInformation.Properties[dirNameAttribName].LineNumber);
            }

            VirtualPath codeVirtualSubDir = HttpRuntime.CodeDirectoryVirtualPath.SimpleCombineWithDir(directoryName);

            // Make sure the specified directory exists
            if (!VirtualPathProvider.DirectoryExistsNoThrow(codeVirtualSubDir))
            {
                throw new ConfigurationErrorsException(
                          SR.GetString(SR.Invalid_CodeSubDirectory_Not_Exist, codeVirtualSubDir),
                          ElementInformation.Properties[dirNameAttribName].Source, ElementInformation.Properties[dirNameAttribName].LineNumber);
            }

            // Look at the actual physical dir to get its name canonicalized (VSWhidbey 288568)
            string       physicalDir = codeVirtualSubDir.MapPathInternal();
            FindFileData ffd;

            FindFileData.FindFile(physicalDir, out ffd);

            // If the name was not canonical, reject it
            if (!StringUtil.EqualsIgnoreCase(directoryName, ffd.FileNameLong))
            {
                throw new ConfigurationErrorsException(
                          SR.GetString(SR.Invalid_CodeSubDirectory, directoryName),
                          ElementInformation.Properties[dirNameAttribName].Source, ElementInformation.Properties[dirNameAttribName].LineNumber);
            }

            if (BuildManager.IsReservedAssemblyName(directoryName))
            {
                throw new ConfigurationErrorsException(
                          SR.GetString(SR.Reserved_AssemblyName, directoryName),
                          ElementInformation.Properties[dirNameAttribName].Source, ElementInformation.Properties[dirNameAttribName].LineNumber);
            }
        }
Beispiel #6
0
 private static bool VirtualDirectoryExistsWithAssert(VirtualPath virtualDir)
 {
     try
     {
         string path = virtualDir.MapPathInternal();
         if (path != null)
         {
             new FileIOPermission(FileIOPermissionAccess.Read, path).Assert();
         }
         return(virtualDir.DirectoryExists());
     }
     catch
     {
         return(false);
     }
 }
        internal MapPathBasedVirtualPathEnumerator(VirtualPath virtualPath, RequestedEntryType requestedEntryType)
        {
            if (virtualPath.IsRelative)
            {
                throw new ArgumentException(SR.GetString(SR.Invalid_app_VirtualPath), "virtualPath");
            }

            _virtualPath        = virtualPath;
            _requestedEntryType = requestedEntryType;

            string physicalPath;

            if (!ServerConfig.UseServerConfig)
            {
                // Use the hosting environment to map the virtual path
                physicalPath = _virtualPath.MapPathInternal();
            }
            else
            {
                IServerConfig serverConfig = ServerConfig.GetInstance();
                _serverConfig2 = serverConfig as IServerConfig2;

                // Use serverConfig to map the virtual path
                physicalPath = serverConfig.MapPath(null, _virtualPath);

                if (_requestedEntryType != RequestedEntryType.Files)
                {
                    // For MetabaseServerConfig, get the subdirs that are not in the application, and add them to the exclude list.
                    if (_serverConfig2 == null)
                    {
                        string [] virtualSubdirsNotInApp = serverConfig.GetVirtualSubdirs(_virtualPath, false);
                        if (virtualSubdirsNotInApp != null)
                        {
                            _exclude = new Hashtable(StringComparer.OrdinalIgnoreCase);
                            foreach (string subdir in virtualSubdirsNotInApp)
                            {
                                _exclude[subdir] = subdir;
                            }
                        }
                    }

                    // Get subdirs that are virtual directories, and record their physical mappings.
                    // Ignore the virtualPaths if we only need files, since it only contains directories
                    string [] virtualSubdirsInApp = serverConfig.GetVirtualSubdirs(_virtualPath, true);
                    if (virtualSubdirsInApp != null)
                    {
                        _virtualPaths = new Hashtable(StringComparer.OrdinalIgnoreCase);
                        foreach (string subdir in virtualSubdirsInApp)
                        {
                            VirtualPath subpath         = _virtualPath.SimpleCombineWithDir(subdir);
                            string      subPhysicalPath = serverConfig.MapPath(null, subpath);
                            if (FileUtil.DirectoryExists(subPhysicalPath))
                            {
                                _virtualPaths[subdir] = new MapPathBasedVirtualDirectory(subpath.VirtualPathString);
                            }
                        }

                        // Create enumerator for the virtual paths
                        _virtualEnumerator = _virtualPaths.Values.GetEnumerator();
                    }
                }
            }

            // Create an enumerator for the physical files and directories at this path
            _fileEnumerator = FileEnumerator.Create(physicalPath);

            // Reset the enumerator. Note that we don't support the Reset method.
            _useFileEnumerator = false;
        }
 internal static string GetDirectoryHash(VirtualPath virtualDir) {
     HashCodeCombiner hashCodeCombiner = new HashCodeCombiner();
     hashCodeCombiner.AddDirectory(virtualDir.MapPathInternal());
     return hashCodeCombiner.CombinedHashString;
 }
        ///
        /// Open a stream from either a virtual or physical path, and if possible get a CacheDependency
        /// for the resulting Stream.
        ///
        internal Stream OpenFileAndGetDependency(VirtualPath virtualPath, string physicalPath, out CacheDependency dependency) {

            // Only one of the paths should be non-null
            Debug.Assert((virtualPath == null) != (physicalPath == null));

            // If we got a virtual path, and we're using the default VPP, call MapPath
            if (physicalPath == null && HostingEnvironment.UsingMapPathBasedVirtualPathProvider) {
                physicalPath = virtualPath.MapPathInternal(TemplateControlVirtualDirectory,
                    true /*allowCrossAppMapping*/);
            }

            Stream stream;
            if (physicalPath != null) {
                // Security check
                HttpRuntime.CheckFilePermission(physicalPath);

                // Work directly with the physical file, bypassing the VPP
                stream = new FileStream(physicalPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                dependency = new CacheDependency(0, physicalPath);
            }
            else {
                // It's non file system based, so go though the VirtualPathProvider
                stream = virtualPath.OpenFile();
                dependency = VirtualPathProvider.GetCacheDependency(virtualPath);
            }

            return stream;
        }
    private static bool VirtualDirectoryExistsWithAssert(VirtualPath virtualDir) {
        try {
            String physicalDir = virtualDir.MapPathInternal();
            if (physicalDir != null) {
                new FileIOPermission(FileIOPermissionAccess.Read, physicalDir).Assert();
            }

            return virtualDir.DirectoryExists();
        }
        catch {
            return false;
        }
    }
    internal static bool VirtualFileExistsWithAssert(VirtualPath virtualPath) {
        string physicalDir = virtualPath.MapPathInternal();

        if (physicalDir != null) {
            (InternalSecurityPermissions.PathDiscovery(physicalDir)).Assert();
        }

        return virtualPath.FileExists();
    }
    internal MapPathBasedVirtualPathEnumerator(VirtualPath virtualPath, RequestedEntryType requestedEntryType) {

        if (virtualPath.IsRelative) {
            throw new ArgumentException(SR.GetString(SR.Invalid_app_VirtualPath), "virtualPath");
        }

        _virtualPath = virtualPath;
        _requestedEntryType = requestedEntryType;

        string physicalPath;
        if (!ServerConfig.UseServerConfig) {
            // Use the hosting environment to map the virtual path
            physicalPath = _virtualPath.MapPathInternal();
        }
        else {
            IServerConfig serverConfig = ServerConfig.GetInstance();
            _serverConfig2 = serverConfig as IServerConfig2;
            
            // Use serverConfig to map the virtual path
            physicalPath = serverConfig.MapPath(null, _virtualPath);

            if (_requestedEntryType != RequestedEntryType.Files) {
                // For MetabaseServerConfig, get the subdirs that are not in the application, and add them to the exclude list.
                if (_serverConfig2 == null) {
                    string [] virtualSubdirsNotInApp = serverConfig.GetVirtualSubdirs(_virtualPath, false);
                    if (virtualSubdirsNotInApp != null) {
                        _exclude = new Hashtable(StringComparer.OrdinalIgnoreCase);
                        foreach (string subdir in virtualSubdirsNotInApp) {
                            _exclude[subdir] = subdir;
                        }
                    }
                }

                // Get subdirs that are virtual directories, and record their physical mappings.
                // Ignore the virtualPaths if we only need files, since it only contains directories
                string [] virtualSubdirsInApp = serverConfig.GetVirtualSubdirs(_virtualPath, true);
                if (virtualSubdirsInApp != null) {
                    _virtualPaths = new Hashtable(StringComparer.OrdinalIgnoreCase);
                    foreach (string subdir in virtualSubdirsInApp) {
                        VirtualPath subpath = _virtualPath.SimpleCombineWithDir(subdir);
                        string subPhysicalPath = serverConfig.MapPath(null, subpath);
                        if (FileUtil.DirectoryExists(subPhysicalPath)) {
                            _virtualPaths[subdir] = new MapPathBasedVirtualDirectory(subpath.VirtualPathString);
                        }
                    }

                    // Create enumerator for the virtual paths
                    _virtualEnumerator = _virtualPaths.Values.GetEnumerator();
                }
            }
        }

        // Create an enumerator for the physical files and directories at this path
        _fileEnumerator = FileEnumerator.Create(physicalPath);

        // Reset the enumerator. Note that we don't support the Reset method.
        _useFileEnumerator = false;
    }
    internal override string ComputeSourceDependenciesHashCode(VirtualPath virtualPath) {

        // If no virtual path was passed in, use the one from the BuildResult
        if (virtualPath == null)
            virtualPath = VirtualPath;

        // We don't want to use the default ComputeSourceDependenciesHashCode imnplementation,
        // as it would use all files in the resources dir to calculate the hash.  Instead,
        // we only want the hash the be based on the culture neutral resources, so that
        // changes to culture specific files don't cause a rebuild of the main res assembly
        HashCodeCombiner hashCodeCombiner = new HashCodeCombiner();
        hashCodeCombiner.AddResourcesDirectory(virtualPath.MapPathInternal());
        return hashCodeCombiner.CombinedHashString;
    }