Ejemplo n.º 1
0
        internal MapPathBasedVirtualPathEnumerator(VirtualPath virtualPath, RequestedEntryType requestedEntryType)
        {
            string str;

            if (virtualPath.IsRelative)
            {
                throw new ArgumentException(System.Web.SR.GetString("Invalid_app_VirtualPath"), "virtualPath");
            }
            this._virtualPath        = virtualPath;
            this._requestedEntryType = requestedEntryType;
            if (!ServerConfig.UseServerConfig)
            {
                str = this._virtualPath.MapPathInternal();
            }
            else
            {
                IServerConfig instance = ServerConfig.GetInstance();
                this._serverConfig2 = instance as IServerConfig2;
                str = instance.MapPath(null, this._virtualPath);
                if (this._requestedEntryType != RequestedEntryType.Files)
                {
                    if (this._serverConfig2 == null)
                    {
                        string[] strArray = instance.GetVirtualSubdirs(this._virtualPath, false);
                        if (strArray != null)
                        {
                            this._exclude = new Hashtable(StringComparer.OrdinalIgnoreCase);
                            foreach (string str2 in strArray)
                            {
                                this._exclude[str2] = str2;
                            }
                        }
                    }
                    string[] virtualSubdirs = instance.GetVirtualSubdirs(this._virtualPath, true);
                    if (virtualSubdirs != null)
                    {
                        this._virtualPaths = new Hashtable(StringComparer.OrdinalIgnoreCase);
                        foreach (string str3 in virtualSubdirs)
                        {
                            VirtualPath path = this._virtualPath.SimpleCombineWithDir(str3);
                            if (FileUtil.DirectoryExists(instance.MapPath(null, path)))
                            {
                                this._virtualPaths[str3] = new MapPathBasedVirtualDirectory(path.VirtualPathString);
                            }
                        }
                        this._virtualEnumerator = this._virtualPaths.Values.GetEnumerator();
                    }
                }
            }
            this._fileEnumerator    = FileEnumerator.Create(str);
            this._useFileEnumerator = false;
        }
Ejemplo n.º 2
0
        internal ISAPIApplicationHost(string appIdOrVirtualPath, string physicalPath, bool validatePhysicalPath, IProcessHostSupportFunctions functions, string iisVersion = null)
        {
            _iisVersion = iisVersion;
            // appIdOrVirtualPath is either a full metabase path, or just a virtual path
            // e.g. /LM/W3SVC/1/Root/MyApp ot /MyApp
            // Figure out which one we have, and get the other one from it
            _functions = functions;

            // make sure the functions are set in the default domain
            if (null == _functions)
            {
                ProcessHost h = ProcessHost.DefaultHost;

                if (null != h)
                {
                    _functions = h.SupportFunctions;

                    if (null != _functions)
                    {
                        HostingEnvironment.SupportFunctions = _functions;
                    }
                }
            }

            IServerConfig serverConfig = ServerConfig.GetDefaultDomainInstance(_iisVersion);

            if (StringUtil.StringStartsWithIgnoreCase(appIdOrVirtualPath, LMW3SVC_PREFIX))
            {
                _appId       = appIdOrVirtualPath;
                _virtualPath = VirtualPath.Create(ExtractVPathFromAppId(_appId));
                _siteID      = ExtractSiteIdFromAppId(_appId);
                _siteName    = serverConfig.GetSiteNameFromSiteID(_siteID);
            }
            else
            {
                _virtualPath = VirtualPath.Create(appIdOrVirtualPath);
                _appId       = GetDefaultAppIdFromVPath(_virtualPath.VirtualPathString);
                _siteID      = DEFAULT_SITEID;
                _siteName    = serverConfig.GetSiteNameFromSiteID(_siteID);
            }

            // Get the physical path from the virtual path if it wasn't passed in
            if (physicalPath == null)
            {
                _physicalPath = serverConfig.MapPath(this, _virtualPath);
            }
            else
            {
                _physicalPath = physicalPath;
            }

            if (validatePhysicalPath)
            {
                if (!Directory.Exists(_physicalPath))
                {
                    throw new HttpException(SR.GetString(SR.Invalid_IIS_app, appIdOrVirtualPath));
                }
            }
        }
Ejemplo n.º 3
0
        internal ISAPIApplicationHost(string appIdOrVirtualPath, string physicalPath, bool validatePhysicalPath, IProcessHostSupportFunctions functions, string iisVersion = null)
        {
            this._iisVersion = iisVersion;
            this._functions  = functions;
            if (this._functions == null)
            {
                ProcessHost defaultHost = ProcessHost.DefaultHost;
                if (defaultHost != null)
                {
                    this._functions = defaultHost.SupportFunctions;
                    if (this._functions != null)
                    {
                        HostingEnvironment.SupportFunctions = this._functions;
                    }
                }
            }
            IServerConfig defaultDomainInstance = ServerConfig.GetDefaultDomainInstance(this._iisVersion);

            if (StringUtil.StringStartsWithIgnoreCase(appIdOrVirtualPath, "/LM/W3SVC/"))
            {
                this._appId       = appIdOrVirtualPath;
                this._virtualPath = VirtualPath.Create(ExtractVPathFromAppId(this._appId));
                this._siteID      = ExtractSiteIdFromAppId(this._appId);
                this._siteName    = defaultDomainInstance.GetSiteNameFromSiteID(this._siteID);
            }
            else
            {
                this._virtualPath = VirtualPath.Create(appIdOrVirtualPath);
                this._appId       = GetDefaultAppIdFromVPath(this._virtualPath.VirtualPathString);
                this._siteID      = "1";
                this._siteName    = defaultDomainInstance.GetSiteNameFromSiteID(this._siteID);
            }
            if (physicalPath == null)
            {
                this._physicalPath = defaultDomainInstance.MapPath(this, this._virtualPath);
            }
            else
            {
                this._physicalPath = physicalPath;
            }
            if (validatePhysicalPath && !Directory.Exists(this._physicalPath))
            {
                throw new HttpException(System.Web.SR.GetString("Invalid_IIS_app", new object[] { appIdOrVirtualPath }));
            }
        }
        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;
        }