コード例 #1
0
        public override void InitForConfiguration(ref string locationSubPath, out string configPath, out string locationConfigPath, IInternalConfigRoot configRoot, params object[] hostInitConfigurationParams)
        {
            WebLevel             webLevel    = (WebLevel)hostInitConfigurationParams[0];
            ConfigurationFileMap fileMap     = (ConfigurationFileMap)hostInitConfigurationParams[1];
            VirtualPath          virtualPath = VirtualPath.CreateAbsoluteAllowNull((string)hostInitConfigurationParams[2]);
            string site = (string)hostInitConfigurationParams[3];

            if (locationSubPath == null)
            {
                locationSubPath = (string)hostInitConfigurationParams[4];
            }
            base.Host.Init(configRoot, hostInitConfigurationParams);
            this.ChooseAndInitConfigMapPath(false, null, fileMap);
            GetConfigPaths(this._configMapPath, webLevel, virtualPath, site, locationSubPath, out this._appPath, out this._appSiteName, out this._appSiteID, out configPath, out locationConfigPath);
            this._appConfigPath = GetConfigPathFromSiteIDAndVPath(this._appSiteID, this._appPath);
            if (IsVirtualPathConfigPath(configPath))
            {
                string      str2;
                VirtualPath path2;
                string      str3;
                GetSiteIDAndVPathFromConfigPath(configPath, out str2, out path2);
                if (this._configMapPath2 != null)
                {
                    str3 = this._configMapPath2.MapPath(str2, path2);
                }
                else
                {
                    str3 = this._configMapPath.MapPath(str2, path2.VirtualPathString);
                }
                if (string.IsNullOrEmpty(str3))
                {
                    throw new ArgumentOutOfRangeException("site");
                }
            }
        }
コード例 #2
0
        public override void InitForConfiguration(ref string locationSubPath, out string configPath, out string locationConfigPath,
                                                  IInternalConfigRoot configRoot, params object[] hostInitConfigurationParams)
        {
            WebLevel             webLevel = (WebLevel)hostInitConfigurationParams[0];
            ConfigurationFileMap fileMap  = (ConfigurationFileMap)hostInitConfigurationParams[1];
            VirtualPath          path     = VirtualPath.CreateAbsoluteAllowNull((string)hostInitConfigurationParams[2]);
            string site = (string)hostInitConfigurationParams[3];

            if (locationSubPath == null)
            {
                locationSubPath = (string)hostInitConfigurationParams[4];
            }

            Host.Init(configRoot, hostInitConfigurationParams);

            // Choose the implementation of IConfigMapPath.
            ChooseAndInitConfigMapPath(false, null, fileMap);

            // Get the configuration paths and application information
            GetConfigPaths(_configMapPath, webLevel, path, site, locationSubPath, out _appPath, out _appSiteName, out _appSiteID, out configPath, out locationConfigPath);
            _appConfigPath = GetConfigPathFromSiteIDAndVPath(_appSiteID, _appPath);

            // Verify that the site and path arguments represent a valid name
            // For example, in Cassini app, which is running on \myApp, a page can
            // ask for the config for "\", which can't map to anything.  We want
            // to catch this kind of error.  Another example is if we're given
            // an invalid site id.
            if (IsVirtualPathConfigPath(configPath))
            {
                string      finalSiteID;
                VirtualPath finalPath;
                GetSiteIDAndVPathFromConfigPath(configPath, out finalSiteID, out finalPath);

                string physicalPath;

                // attempt to use IConfigMapPath2 if provider supports it
                if (null != _configMapPath2)
                {
                    physicalPath = _configMapPath2.MapPath(finalSiteID, finalPath);
                }
                else
                {
                    physicalPath = _configMapPath.MapPath(finalSiteID, finalPath.VirtualPathString);
                }

                if (String.IsNullOrEmpty(physicalPath))
                {
                    throw new ArgumentOutOfRangeException("site");
                }
            }

#if DBG
            _inited = true;
#endif
        }
コード例 #3
0
        private static System.Configuration.Configuration OpenWebConfigurationImpl(WebLevel webLevel, ConfigurationFileMap fileMap, string path, string site, string locationSubPath, string server, string userName, string password, IntPtr userToken)
        {
            VirtualPath path2;

            if (HostingEnvironment.IsHosted)
            {
                path2 = VirtualPath.CreateNonRelativeAllowNull(path);
            }
            else
            {
                path2 = VirtualPath.CreateAbsoluteAllowNull(path);
            }
            return(WebConfigurationHost.OpenConfiguration(webLevel, fileMap, path2, site, locationSubPath, server, userName, password, userToken));
        }
コード例 #4
0
        public string GetFilePaths(int webLevelAsInt, string path, string site, string locationSubPath)
        {
            string         str;
            string         str2;
            VirtualPath    path3;
            string         str3;
            string         str4;
            string         str5;
            VirtualPath    path4;
            WebLevel       webLevel = (WebLevel)webLevelAsInt;
            IConfigMapPath instance = IISMapPath.GetInstance();

            WebConfigurationHost.GetConfigPaths(instance, webLevel, VirtualPath.CreateNonRelativeAllowNull(path), site, locationSubPath, out path3, out str, out str2, out str3, out str4);
            ArrayList list = new ArrayList();

            list.Add(VirtualPath.GetVirtualPathString(path3));
            list.Add(str);
            list.Add(str2);
            list.Add(str3);
            list.Add(str4);
            WebConfigurationHost.GetSiteIDAndVPathFromConfigPath(str3, out str5, out path4);
            list.Add("machine");
            list.Add(HttpConfigurationSystem.MachineConfigurationFilePath);
            if (webLevel != WebLevel.Machine)
            {
                list.Add("machine/webroot");
                list.Add(HttpConfigurationSystem.RootWebConfigurationFilePath);
                for (VirtualPath path5 = path4; path5 != null; path5 = path5.Parent)
                {
                    string configPathFromSiteIDAndVPath = WebConfigurationHost.GetConfigPathFromSiteIDAndVPath(str2, path5);
                    string str7 = Path.Combine(instance.MapPath(str2, path5.VirtualPathString), "web.config");
                    list.Add(configPathFromSiteIDAndVPath);
                    list.Add(str7);
                }
            }
            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < list.Count; i++)
            {
                if (i > 0)
                {
                    builder.Append('<');
                }
                string str8 = (string)list[i];
                builder.Append(str8);
            }
            return(builder.ToString());
        }
コード例 #5
0
        //
        // *************************************************
        // ** Static Management Functions to edit config **
        // *************************************************
        //

        private static Configuration OpenWebConfigurationImpl(
                WebLevel webLevel, ConfigurationFileMap fileMap, string path, string site, string locationSubPath, 
                string server, string userName, string password, IntPtr userToken) {

            // In the hosted case, we allow app relative (~/....).  Otherwise, it must be absolute
            VirtualPath virtualPath;
            if (HostingEnvironment.IsHosted) {
                virtualPath = VirtualPath.CreateNonRelativeAllowNull(path);
            }
            else {
                virtualPath = VirtualPath.CreateAbsoluteAllowNull(path);
            }

            return WebConfigurationHost.OpenConfiguration(webLevel, fileMap, virtualPath, site, locationSubPath, 
                    server, userName, password, userToken);
        }
コード例 #6
0
        internal static System.Configuration.Configuration OpenConfiguration(WebLevel webLevel, ConfigurationFileMap fileMap, VirtualPath path, string site, string locationSubPath, string server, string userName, string password, IntPtr tokenHandle)
        {
            if (!IsValidSiteArgument(site))
            {
                throw System.Web.Util.ExceptionUtil.ParameterInvalid("site");
            }
            locationSubPath = ConfigurationFactory.NormalizeLocationSubPath(locationSubPath, null);
            if ((((!string.IsNullOrEmpty(server) && (server != ".")) && (!System.Web.Util.StringUtil.EqualsIgnoreCase(server, "127.0.0.1") && !System.Web.Util.StringUtil.EqualsIgnoreCase(server, "::1"))) && !System.Web.Util.StringUtil.EqualsIgnoreCase(server, "localhost")) && !System.Web.Util.StringUtil.EqualsIgnoreCase(server, Environment.MachineName))
            {
                object[] hostInitConfigurationParams = new object[9];
                hostInitConfigurationParams[0] = webLevel;
                hostInitConfigurationParams[2] = VirtualPath.GetVirtualPathString(path);
                hostInitConfigurationParams[3] = site;
                hostInitConfigurationParams[4] = locationSubPath;
                hostInitConfigurationParams[5] = server;
                hostInitConfigurationParams[6] = userName;
                hostInitConfigurationParams[7] = password;
                hostInitConfigurationParams[8] = tokenHandle;
                return(ConfigurationFactory.Create(typeof(RemoteWebConfigurationHost), hostInitConfigurationParams));
            }
            if (string.IsNullOrEmpty(server))
            {
                if (!string.IsNullOrEmpty(userName))
                {
                    throw System.Web.Util.ExceptionUtil.ParameterInvalid("userName");
                }
                if (!string.IsNullOrEmpty(password))
                {
                    throw System.Web.Util.ExceptionUtil.ParameterInvalid("password");
                }
                if (tokenHandle != IntPtr.Zero)
                {
                    throw System.Web.Util.ExceptionUtil.ParameterInvalid("tokenHandle");
                }
            }
            if (fileMap != null)
            {
                fileMap = (ConfigurationFileMap)fileMap.Clone();
            }
            WebConfigurationFileMap map = fileMap as WebConfigurationFileMap;

            if ((map != null) && !string.IsNullOrEmpty(site))
            {
                map.Site = site;
            }
            return(ConfigurationFactory.Create(typeof(WebConfigurationHost), new object[] { webLevel, fileMap, VirtualPath.GetVirtualPathString(path), site, locationSubPath }));
        }
コード例 #7
0
        //
        // *************************************************
        // ** Static Management Functions to edit config **
        // *************************************************
        //

        private static Configuration OpenWebConfigurationImpl(
            WebLevel webLevel, ConfigurationFileMap fileMap, string path, string site, string locationSubPath,
            string server, string userName, string password, IntPtr userToken)
        {
            // In the hosted case, we allow app relative (~/....).  Otherwise, it must be absolute
            VirtualPath virtualPath;

            if (HostingEnvironment.IsHosted)
            {
                virtualPath = VirtualPath.CreateNonRelativeAllowNull(path);
            }
            else
            {
                virtualPath = VirtualPath.CreateAbsoluteAllowNull(path);
            }

            return(WebConfigurationHost.OpenConfiguration(webLevel, fileMap, virtualPath, site, locationSubPath,
                                                          server, userName, password, userToken));
        }
コード例 #8
0
        public string GetFilePaths(int webLevelAsInt, string path, string site, string locationSubPath)
        {
            WebLevel webLevel = (WebLevel)webLevelAsInt;

            IConfigMapPath configMapPath = IISMapPath.GetInstance();

            // Get the configuration paths and application information
            string      appSiteName, appSiteID;
            VirtualPath appPath;
            string      configPath, locationConfigPath;

            WebConfigurationHost.GetConfigPaths(configMapPath, webLevel, VirtualPath.CreateNonRelativeAllowNull(path), site, locationSubPath,
                                                out appPath, out appSiteName, out appSiteID, out configPath, out locationConfigPath);

            //
            // Format of filePaths:
            //      appPath < appSiteName < appSiteID < configPath < locationConfigPath [< configPath < fileName]+
            //
            ArrayList filePaths = new ArrayList();

            filePaths.Add(VirtualPath.GetVirtualPathString(appPath));
            filePaths.Add(appSiteName);
            filePaths.Add(appSiteID);
            filePaths.Add(configPath);
            filePaths.Add(locationConfigPath);

            string      dummySiteID;
            VirtualPath virtualPath;

            WebConfigurationHost.GetSiteIDAndVPathFromConfigPath(configPath, out dummySiteID, out virtualPath);

            // pathmap for machine.config
            filePaths.Add(WebConfigurationHost.MachineConfigPath);
            filePaths.Add(HttpConfigurationSystem.MachineConfigurationFilePath);

            // pathmap for root web.config
            if (webLevel != WebLevel.Machine)
            {
                filePaths.Add(WebConfigurationHost.RootWebConfigPath);
                filePaths.Add(HttpConfigurationSystem.RootWebConfigurationFilePath);

                // pathmap for other paths
                for (VirtualPath currentVirtualPath = virtualPath; currentVirtualPath != null; currentVirtualPath = currentVirtualPath.Parent)
                {
                    string currentConfigPath = WebConfigurationHost.GetConfigPathFromSiteIDAndVPath(appSiteID, currentVirtualPath);
                    string currentFilePath   = configMapPath.MapPath(appSiteID, currentVirtualPath.VirtualPathString);
                    currentFilePath = System.IO.Path.Combine(currentFilePath, HttpConfigurationSystem.WebConfigFileName);

                    filePaths.Add(currentConfigPath);
                    filePaths.Add(currentFilePath);
                }
            }

            // join into a single string
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < filePaths.Count; i++)
            {
                if (i > 0)
                {
                    sb.Append(FilePathsSeparatorChar);
                }

                string part = (string)filePaths[i];
                sb.Append(part);
            }

            return(sb.ToString());
        }
コード例 #9
0
        // Create an instance of a Configuration object.
        // Used by design-time API to open a Configuration object.
        static internal Configuration OpenConfiguration(
            WebLevel webLevel, ConfigurationFileMap fileMap, VirtualPath path, string site, string locationSubPath,
            string server, string userName, string password, IntPtr tokenHandle)
        {
            Configuration configuration;

            if (!IsValidSiteArgument(site))
            {
                throw ExceptionUtil.ParameterInvalid("site");
            }

            locationSubPath = ConfigurationFactory.NormalizeLocationSubPath(locationSubPath, null);

            bool isRemote = !String.IsNullOrEmpty(server) &&
                            server != "." &&
                            !StringUtil.EqualsIgnoreCase(server, "127.0.0.1") &&
                            !StringUtil.EqualsIgnoreCase(server, "::1") &&
                            !StringUtil.EqualsIgnoreCase(server, "localhost") &&
                            !StringUtil.EqualsIgnoreCase(server, Environment.MachineName);


            if (isRemote)
            {
                configuration = ConfigurationFactory.Create(typeof(RemoteWebConfigurationHost),
                                                            webLevel, null, VirtualPath.GetVirtualPathString(path), site, locationSubPath, server, userName, password, tokenHandle);
            }
            else
            {
                if (String.IsNullOrEmpty(server))
                {
                    if (!String.IsNullOrEmpty(userName))
                    {
                        throw ExceptionUtil.ParameterInvalid("userName");
                    }

                    if (!String.IsNullOrEmpty(password))
                    {
                        throw ExceptionUtil.ParameterInvalid("password");
                    }

                    if (tokenHandle != (IntPtr)0)
                    {
                        throw ExceptionUtil.ParameterInvalid("tokenHandle");
                    }
                }

                // Create a copy of the fileMap, so that it cannot be altered by
                // its creator once we start using it.
                if (fileMap != null)
                {
                    fileMap = (ConfigurationFileMap)fileMap.Clone();
                }

                WebConfigurationFileMap webFileMap = fileMap as WebConfigurationFileMap;
                if (webFileMap != null && !String.IsNullOrEmpty(site))
                {
                    webFileMap.Site = site;
                }

                configuration = ConfigurationFactory.Create(typeof(WebConfigurationHost),
                                                            webLevel, fileMap, VirtualPath.GetVirtualPathString(path), site, locationSubPath);
            }

            return(configuration);
        }
コード例 #10
0
        // Not used in runtime because in runtime we have all the siteid, appPath, etc. already.
        static internal void GetConfigPaths(IConfigMapPath configMapPath, WebLevel webLevel, VirtualPath virtualPath, string site, string locationSubPath,
                                            out VirtualPath appPath, out string appSiteName, out string appSiteID, out string configPath, out string locationConfigPath)
        {
            appPath     = null;
            appSiteName = null;
            appSiteID   = null;

            if (webLevel == WebLevel.Machine || virtualPath == null)
            {
                // Site is meaningless at machine and root web.config level
                // However, we allow a site parameter if the caller is opening
                // a location tag.  See VSWhidbey 548361.
                if (!String.IsNullOrEmpty(site) && String.IsNullOrEmpty(locationSubPath))
                {
                    throw ExceptionUtil.ParameterInvalid("site");
                }

                if (webLevel == WebLevel.Machine)
                {
                    configPath = MachineConfigPath;
                }
                else
                {
                    configPath = RootWebConfigPath;
                }
            }
            else
            {
                // Get the site name and ID
                if (!String.IsNullOrEmpty(site))
                {
                    configMapPath.ResolveSiteArgument(site, out appSiteName, out appSiteID);

                    if (String.IsNullOrEmpty(appSiteID))
                    {
                        throw new InvalidOperationException(SR.GetString(SR.Config_failed_to_resolve_site_id, site));
                    }
                }
                else
                {
                    // If site not supplied, try hosting environment first
                    if (HostingEnvironment.IsHosted)
                    {
                        appSiteName = HostingEnvironment.SiteNameNoDemand;
                        appSiteID   = HostingEnvironment.SiteID;
                    }

                    // Rely on defaults if not provided in hosting environment
                    if (String.IsNullOrEmpty(appSiteID))
                    {
                        configMapPath.GetDefaultSiteNameAndID(out appSiteName, out appSiteID);
                    }

                    Debug.Assert(!String.IsNullOrEmpty(appSiteID), "No appSiteID found when site argument is null");
                }

                configPath = GetConfigPathFromSiteIDAndVPath(appSiteID, virtualPath);
            }

            // get locationConfigPath
            locationConfigPath = null;
            string      locationSite  = null;
            VirtualPath locationVPath = null;

            if (locationSubPath != null)
            {
                locationConfigPath = GetConfigPathFromLocationSubPathBasic(configPath, locationSubPath);
                GetSiteIDAndVPathFromConfigPath(locationConfigPath, out locationSite, out locationVPath);

                // If we're at machine or root web.config level and a location path is given,
                // handle the site part of the location path.
                if (String.IsNullOrEmpty(appSiteID) && !String.IsNullOrEmpty(locationSite))
                {
                    configMapPath.ResolveSiteArgument(locationSite, out appSiteName, out appSiteID);
                    if (!String.IsNullOrEmpty(appSiteID))
                    {
                        // Recompose the location config path based on new appSiteID
                        locationConfigPath = GetConfigPathFromSiteIDAndVPath(appSiteID, locationVPath);
                    }
                    else
                    {
                        // If there is no path, then allow the location to be edited,
                        // as we don't need to map elements of the path.
                        if (locationVPath == null || locationVPath.VirtualPathString == "/")
                        {
                            appSiteName = locationSite;
                            appSiteID   = locationSite;
                        }
                        // Otherwise, the site argument is ambiguous.
                        else
                        {
                            //

                            appSiteName = null;
                            appSiteID   = null;
                        }
                    }
                }
            }

            // get appPath
            string appPathString = null;

            if (locationVPath != null)
            {
                appPathString = configMapPath.GetAppPathForPath(appSiteID, locationVPath.VirtualPathString);
            }
            else if (virtualPath != null)
            {
                appPathString = configMapPath.GetAppPathForPath(appSiteID, virtualPath.VirtualPathString);
            }

            if (appPathString != null)
            {
                appPath = VirtualPath.Create(appPathString);
            }
        }
コード例 #11
0
        internal static void GetConfigPaths(IConfigMapPath configMapPath, WebLevel webLevel, VirtualPath virtualPath, string site, string locationSubPath, out VirtualPath appPath, out string appSiteName, out string appSiteID, out string configPath, out string locationConfigPath)
        {
            appPath     = null;
            appSiteName = null;
            appSiteID   = null;
            if ((webLevel == WebLevel.Machine) || (virtualPath == null))
            {
                if (!string.IsNullOrEmpty(site) && string.IsNullOrEmpty(locationSubPath))
                {
                    throw System.Web.Util.ExceptionUtil.ParameterInvalid("site");
                }
                if (webLevel == WebLevel.Machine)
                {
                    configPath = "machine";
                }
                else
                {
                    configPath = "machine/webroot";
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(site))
                {
                    configMapPath.ResolveSiteArgument(site, out appSiteName, out appSiteID);
                    if (string.IsNullOrEmpty(appSiteID))
                    {
                        throw new InvalidOperationException(System.Web.SR.GetString("Config_failed_to_resolve_site_id", new object[] { site }));
                    }
                }
                else
                {
                    if (HostingEnvironment.IsHosted)
                    {
                        appSiteName = HostingEnvironment.SiteNameNoDemand;
                        appSiteID   = HostingEnvironment.SiteID;
                    }
                    if (string.IsNullOrEmpty(appSiteID))
                    {
                        configMapPath.GetDefaultSiteNameAndID(out appSiteName, out appSiteID);
                    }
                }
                configPath = GetConfigPathFromSiteIDAndVPath(appSiteID, virtualPath);
            }
            locationConfigPath = null;
            string      siteID = null;
            VirtualPath vpath  = null;

            if (locationSubPath != null)
            {
                locationConfigPath = GetConfigPathFromLocationSubPathBasic(configPath, locationSubPath);
                GetSiteIDAndVPathFromConfigPath(locationConfigPath, out siteID, out vpath);
                if (string.IsNullOrEmpty(appSiteID) && !string.IsNullOrEmpty(siteID))
                {
                    configMapPath.ResolveSiteArgument(siteID, out appSiteName, out appSiteID);
                    if (!string.IsNullOrEmpty(appSiteID))
                    {
                        locationConfigPath = GetConfigPathFromSiteIDAndVPath(appSiteID, vpath);
                    }
                    else if ((vpath == null) || (vpath.VirtualPathString == "/"))
                    {
                        appSiteName = siteID;
                        appSiteID   = siteID;
                    }
                    else
                    {
                        appSiteName = null;
                        appSiteID   = null;
                    }
                }
            }
            string appPathForPath = null;

            if (vpath != null)
            {
                appPathForPath = configMapPath.GetAppPathForPath(appSiteID, vpath.VirtualPathString);
            }
            else if (virtualPath != null)
            {
                appPathForPath = configMapPath.GetAppPathForPath(appSiteID, virtualPath.VirtualPathString);
            }
            if (appPathForPath != null)
            {
                appPath = VirtualPath.Create(appPathForPath);
            }
        }
 internal static System.Configuration.Configuration OpenConfiguration(WebLevel webLevel, ConfigurationFileMap fileMap, VirtualPath path, string site, string locationSubPath, string server, string userName, string password, IntPtr tokenHandle)
 {
     if (!IsValidSiteArgument(site))
     {
         throw System.Web.Util.ExceptionUtil.ParameterInvalid("site");
     }
     locationSubPath = ConfigurationFactory.NormalizeLocationSubPath(locationSubPath, null);
     if ((((!string.IsNullOrEmpty(server) && (server != ".")) && (!System.Web.Util.StringUtil.EqualsIgnoreCase(server, "127.0.0.1") && !System.Web.Util.StringUtil.EqualsIgnoreCase(server, "::1"))) && !System.Web.Util.StringUtil.EqualsIgnoreCase(server, "localhost")) && !System.Web.Util.StringUtil.EqualsIgnoreCase(server, Environment.MachineName))
     {
         object[] hostInitConfigurationParams = new object[9];
         hostInitConfigurationParams[0] = webLevel;
         hostInitConfigurationParams[2] = VirtualPath.GetVirtualPathString(path);
         hostInitConfigurationParams[3] = site;
         hostInitConfigurationParams[4] = locationSubPath;
         hostInitConfigurationParams[5] = server;
         hostInitConfigurationParams[6] = userName;
         hostInitConfigurationParams[7] = password;
         hostInitConfigurationParams[8] = tokenHandle;
         return ConfigurationFactory.Create(typeof(RemoteWebConfigurationHost), hostInitConfigurationParams);
     }
     if (string.IsNullOrEmpty(server))
     {
         if (!string.IsNullOrEmpty(userName))
         {
             throw System.Web.Util.ExceptionUtil.ParameterInvalid("userName");
         }
         if (!string.IsNullOrEmpty(password))
         {
             throw System.Web.Util.ExceptionUtil.ParameterInvalid("password");
         }
         if (tokenHandle != IntPtr.Zero)
         {
             throw System.Web.Util.ExceptionUtil.ParameterInvalid("tokenHandle");
         }
     }
     if (fileMap != null)
     {
         fileMap = (ConfigurationFileMap) fileMap.Clone();
     }
     WebConfigurationFileMap map = fileMap as WebConfigurationFileMap;
     if ((map != null) && !string.IsNullOrEmpty(site))
     {
         map.Site = site;
     }
     return ConfigurationFactory.Create(typeof(WebConfigurationHost), new object[] { webLevel, fileMap, VirtualPath.GetVirtualPathString(path), site, locationSubPath });
 }
 internal static void GetConfigPaths(IConfigMapPath configMapPath, WebLevel webLevel, VirtualPath virtualPath, string site, string locationSubPath, out VirtualPath appPath, out string appSiteName, out string appSiteID, out string configPath, out string locationConfigPath)
 {
     appPath = null;
     appSiteName = null;
     appSiteID = null;
     if ((webLevel == WebLevel.Machine) || (virtualPath == null))
     {
         if (!string.IsNullOrEmpty(site) && string.IsNullOrEmpty(locationSubPath))
         {
             throw System.Web.Util.ExceptionUtil.ParameterInvalid("site");
         }
         if (webLevel == WebLevel.Machine)
         {
             configPath = "machine";
         }
         else
         {
             configPath = "machine/webroot";
         }
     }
     else
     {
         if (!string.IsNullOrEmpty(site))
         {
             configMapPath.ResolveSiteArgument(site, out appSiteName, out appSiteID);
             if (string.IsNullOrEmpty(appSiteID))
             {
                 throw new InvalidOperationException(System.Web.SR.GetString("Config_failed_to_resolve_site_id", new object[] { site }));
             }
         }
         else
         {
             if (HostingEnvironment.IsHosted)
             {
                 appSiteName = HostingEnvironment.SiteNameNoDemand;
                 appSiteID = HostingEnvironment.SiteID;
             }
             if (string.IsNullOrEmpty(appSiteID))
             {
                 configMapPath.GetDefaultSiteNameAndID(out appSiteName, out appSiteID);
             }
         }
         configPath = GetConfigPathFromSiteIDAndVPath(appSiteID, virtualPath);
     }
     locationConfigPath = null;
     string siteID = null;
     VirtualPath vpath = null;
     if (locationSubPath != null)
     {
         locationConfigPath = GetConfigPathFromLocationSubPathBasic(configPath, locationSubPath);
         GetSiteIDAndVPathFromConfigPath(locationConfigPath, out siteID, out vpath);
         if (string.IsNullOrEmpty(appSiteID) && !string.IsNullOrEmpty(siteID))
         {
             configMapPath.ResolveSiteArgument(siteID, out appSiteName, out appSiteID);
             if (!string.IsNullOrEmpty(appSiteID))
             {
                 locationConfigPath = GetConfigPathFromSiteIDAndVPath(appSiteID, vpath);
             }
             else if ((vpath == null) || (vpath.VirtualPathString == "/"))
             {
                 appSiteName = siteID;
                 appSiteID = siteID;
             }
             else
             {
                 appSiteName = null;
                 appSiteID = null;
             }
         }
     }
     string appPathForPath = null;
     if (vpath != null)
     {
         appPathForPath = configMapPath.GetAppPathForPath(appSiteID, vpath.VirtualPathString);
     }
     else if (virtualPath != null)
     {
         appPathForPath = configMapPath.GetAppPathForPath(appSiteID, virtualPath.VirtualPathString);
     }
     if (appPathForPath != null)
     {
         appPath = VirtualPath.Create(appPathForPath);
     }
 }
コード例 #14
0
        public override void InitForConfiguration(ref string locationSubPath, out string configPath, out string locationConfigPath,
                                                  IInternalConfigRoot root, params object[] hostInitConfigurationParams)
        {
            WebLevel webLevel = (WebLevel)hostInitConfigurationParams[0];
            // ConfigurationFileMap    fileMap = (ConfigurationFileMap)    hostInitConfigurationParams[1];
            string path = (string)hostInitConfigurationParams[2];
            string site = (string)hostInitConfigurationParams[3];

            if (locationSubPath == null)
            {
                locationSubPath = (string)hostInitConfigurationParams[4];
            }

            string server      = (string)hostInitConfigurationParams[5];
            string userName    = (string)hostInitConfigurationParams[6];
            string password    = (string)hostInitConfigurationParams[7];
            IntPtr tokenHandle = (IntPtr)hostInitConfigurationParams[8];

            configPath         = null;
            locationConfigPath = null;

            _Server   = server;
            _Username = GetUserNameFromFullName(userName);
            _Domain   = GetDomainFromFullName(userName);
            _Password = password;
            _Identity = (tokenHandle == IntPtr.Zero) ? null : new WindowsIdentity(tokenHandle); //CreateWindowsIdentity(username, domain, password, tokenHandle);

            _PathMap = new Hashtable(StringComparer.OrdinalIgnoreCase);

#if !FEATURE_PAL // FEATURE_PAL does not have WindowsImpersonationContext, COM objects
            //
            // Send the path arguments to the server for parsing,
            // and retreive the normalized paths and path mapping
            // from config paths to file paths.
            //
            string filePaths;
            try {
                WindowsImpersonationContext wiContext = (_Identity != null) ? _Identity.Impersonate() : null;
                try {
                    IRemoteWebConfigurationHostServer remoteSrv = RemoteWebConfigurationHost.CreateRemoteObject(server, _Username, _Domain, password); //(IRemoteWebConfigurationHostServer) Activator.CreateInstance(type);
                    try {
                        filePaths = remoteSrv.GetFilePaths((int)webLevel, path, site, locationSubPath);
                    } finally {
                        // Release COM objects
                        while (Marshal.ReleaseComObject(remoteSrv) > 0)
                        {
                        }
                    }
                } finally {
                    if (wiContext != null)
                    {
                        wiContext.Undo();
                    }
                }
            }
            catch {
                // Wrap finally clause with a try to avoid exception clauses being run
                // while the thread is impersonated.
                throw;
            }

            if (filePaths == null)
            {
                throw ExceptionUtil.UnexpectedError("RemoteWebConfigurationHost::InitForConfiguration");
            }

            //
            // Format of filePaths:
            //      appPath < appSiteName < appSiteID < configPath < locationConfigPath [< configPath < fileName]+
            //
            string[] parts = filePaths.Split(RemoteWebConfigurationHostServer.FilePathsSeparatorParams);

            if (parts.Length < 7 || (parts.Length - 5) % 2 != 0)
            {
                throw ExceptionUtil.UnexpectedError("RemoteWebConfigurationHost::InitForConfiguration");
            }

            // convert empty strings to nulls
            for (int i = 0; i < parts.Length; i++)
            {
                if (parts[i].Length == 0)
                {
                    parts[i] = null;
                }
            }

            // get config paths
            string appPath     = parts[0];
            string appSiteName = parts[1];
            string appSiteID   = parts[2];
            configPath         = parts[3];
            locationConfigPath = parts[4];
            _ConfigPath        = configPath;

            // Create a WebConfigurationFileMap to be used when we later initialize our delegating WebConfigurationHost
            WebConfigurationFileMap configFileMap      = new WebConfigurationFileMap();
            VirtualPath             appPathVirtualPath = VirtualPath.CreateAbsoluteAllowNull(appPath);

            configFileMap.Site = appSiteID;

            // populate the configpath->physical path mapping
            for (int i = 5; i < parts.Length; i += 2)
            {
                string configPathTemp   = parts[i];
                string physicalFilePath = parts[i + 1];

                _PathMap.Add(configPathTemp, physicalFilePath);

                // Update the WebConfigurationFileMap
                if (WebConfigurationHost.IsMachineConfigPath(configPathTemp))
                {
                    configFileMap.MachineConfigFilename = physicalFilePath;
                }
                else
                {
                    string vPathString;
                    bool   isRootApp;

                    if (WebConfigurationHost.IsRootWebConfigPath(configPathTemp))
                    {
                        vPathString = null;
                        isRootApp   = false;
                    }
                    else
                    {
                        VirtualPath vPath;
                        string      dummy;

                        WebConfigurationHost.GetSiteIDAndVPathFromConfigPath(configPathTemp, out dummy, out vPath);
                        vPathString = VirtualPath.GetVirtualPathString(vPath);
                        isRootApp   = (vPath == appPathVirtualPath);
                    }

                    configFileMap.VirtualDirectories.Add(vPathString,
                                                         new VirtualDirectoryMapping(Path.GetDirectoryName(physicalFilePath), isRootApp));
                }
            }
#else // !FEATURE_PAL: set dummy config path
            string appPath = null;
            _ConfigPath = configPath;
#endif // !FEATURE_PAL

            // Delegate to a WebConfigurationHost for unhandled methods.
            WebConfigurationHost webConfigurationHost = new WebConfigurationHost();
            webConfigurationHost.Init(root, true, new UserMapPath(configFileMap, /*pathsAreLocal*/ false), null, appPath, appSiteName, appSiteID);
            Host = webConfigurationHost;
        }
コード例 #15
0
        // Not used in runtime because in runtime we have all the siteid, appPath, etc. already.
        static internal void GetConfigPaths(IConfigMapPath configMapPath, WebLevel webLevel, VirtualPath virtualPath, string site, string locationSubPath,
                out VirtualPath appPath, out string appSiteName, out string appSiteID, out string configPath, out string locationConfigPath) {

            appPath = null;
            appSiteName = null;
            appSiteID = null;

            if (webLevel == WebLevel.Machine || virtualPath == null) {
                // Site is meaningless at machine and root web.config level
                // However, we allow a site parameter if the caller is opening
                // a location tag.  See VSWhidbey 548361.
                if (!String.IsNullOrEmpty(site) && String.IsNullOrEmpty(locationSubPath)) {
                    throw ExceptionUtil.ParameterInvalid("site");
                }

                if (webLevel == WebLevel.Machine) {
                    configPath = MachineConfigPath;
                }
                else {
                    configPath = RootWebConfigPath;
                }
            }
            else {
                // Get the site name and ID
                if (!String.IsNullOrEmpty(site)) {
                    configMapPath.ResolveSiteArgument(site, out appSiteName, out appSiteID);

                    if (String.IsNullOrEmpty(appSiteID)) {
                        throw new InvalidOperationException(SR.GetString(SR.Config_failed_to_resolve_site_id, site));
                    }
                }
                else {
                    // If site not supplied, try hosting environment first
                    if (HostingEnvironment.IsHosted) {
                        appSiteName = HostingEnvironment.SiteNameNoDemand;
                        appSiteID = HostingEnvironment.SiteID;
                    }

                    // Rely on defaults if not provided in hosting environment
                    if (String.IsNullOrEmpty(appSiteID)) {
                        configMapPath.GetDefaultSiteNameAndID(out appSiteName, out appSiteID);
                    }

                    Debug.Assert(!String.IsNullOrEmpty(appSiteID), "No appSiteID found when site argument is null");
                }

                configPath = GetConfigPathFromSiteIDAndVPath(appSiteID, virtualPath);
            }

            // get locationConfigPath
            locationConfigPath = null;
            string locationSite = null;
            VirtualPath locationVPath = null;
            if (locationSubPath != null) {
                locationConfigPath = GetConfigPathFromLocationSubPathBasic(configPath, locationSubPath);
                GetSiteIDAndVPathFromConfigPath(locationConfigPath, out locationSite, out locationVPath);

                // If we're at machine or root web.config level and a location path is given,
                // handle the site part of the location path.
                if (String.IsNullOrEmpty(appSiteID) && !String.IsNullOrEmpty(locationSite)) {
                    configMapPath.ResolveSiteArgument(locationSite, out appSiteName, out appSiteID);
                    if (!String.IsNullOrEmpty(appSiteID)) {
                        // Recompose the location config path based on new appSiteID
                        locationConfigPath = GetConfigPathFromSiteIDAndVPath(appSiteID, locationVPath);
                    }
                    else {
                        // If there is no path, then allow the location to be edited,
                        // as we don't need to map elements of the path.
                        if (locationVPath == null || locationVPath.VirtualPathString == "/") {
                            appSiteName = locationSite;
                            appSiteID = locationSite;
                        }
                        // Otherwise, the site argument is ambiguous.
                        else {
                            // 

                            appSiteName = null;
                            appSiteID = null;
                        }
                    }
                }
            }

            // get appPath
            string appPathString = null;
            if (locationVPath != null) {
                appPathString = configMapPath.GetAppPathForPath(appSiteID, locationVPath.VirtualPathString);
            }
            else if (virtualPath != null) {
                appPathString = configMapPath.GetAppPathForPath(appSiteID, virtualPath.VirtualPathString);
            }

            if (appPathString != null) {
                appPath = VirtualPath.Create(appPathString);
            }
        }
コード例 #16
0
         // Create an instance of a Configuration object.
        // Used by design-time API to open a Configuration object.
        static internal Configuration OpenConfiguration(
                WebLevel webLevel, ConfigurationFileMap fileMap, VirtualPath path, string site, string locationSubPath,
                string server, string userName, string password, IntPtr tokenHandle) {

            Configuration configuration;

            if (!IsValidSiteArgument(site)) {
                throw ExceptionUtil.ParameterInvalid("site");
            }

            locationSubPath = ConfigurationFactory.NormalizeLocationSubPath(locationSubPath, null);

            bool isRemote = !String.IsNullOrEmpty(server)
                && server != "."
                && !StringUtil.EqualsIgnoreCase(server, "127.0.0.1")
                && !StringUtil.EqualsIgnoreCase(server, "::1")
                && !StringUtil.EqualsIgnoreCase(server, "localhost")
                && !StringUtil.EqualsIgnoreCase(server, Environment.MachineName);


            if (isRemote) {
                configuration = ConfigurationFactory.Create(typeof(RemoteWebConfigurationHost),
                    webLevel, null, VirtualPath.GetVirtualPathString(path), site, locationSubPath, server, userName, password, tokenHandle);
            }
            else {
                 if (String.IsNullOrEmpty(server)) {
                    if (!String.IsNullOrEmpty(userName))
                        throw ExceptionUtil.ParameterInvalid("userName");

                    if (!String.IsNullOrEmpty(password))
                        throw ExceptionUtil.ParameterInvalid("password");

                    if (tokenHandle != (IntPtr) 0)
                        throw ExceptionUtil.ParameterInvalid("tokenHandle");
                }

                // Create a copy of the fileMap, so that it cannot be altered by
                // its creator once we start using it.
                if (fileMap != null) {
                    fileMap = (ConfigurationFileMap) fileMap.Clone();
                }

                WebConfigurationFileMap webFileMap = fileMap as WebConfigurationFileMap;
                if (webFileMap != null && !String.IsNullOrEmpty(site)) {
                    webFileMap.Site = site;
                }

                configuration = ConfigurationFactory.Create(typeof(WebConfigurationHost),
                    webLevel, fileMap, VirtualPath.GetVirtualPathString(path), site, locationSubPath );
             }

            return configuration;
        }
コード例 #17
0
        public override void InitForConfiguration(ref string locationSubPath, out string configPath, out string locationConfigPath, IInternalConfigRoot root, params object[] hostInitConfigurationParams)
        {
            string   str6;
            WebLevel level = (WebLevel)hostInitConfigurationParams[0];
            string   str   = (string)hostInitConfigurationParams[2];
            string   site  = (string)hostInitConfigurationParams[3];

            if (locationSubPath == null)
            {
                locationSubPath = (string)hostInitConfigurationParams[4];
            }
            string str3         = (string)hostInitConfigurationParams[5];
            string fullUserName = (string)hostInitConfigurationParams[6];
            string password     = (string)hostInitConfigurationParams[7];
            IntPtr userToken    = (IntPtr)hostInitConfigurationParams[8];

            configPath         = null;
            locationConfigPath = null;
            this._Server       = str3;
            this._Username     = GetUserNameFromFullName(fullUserName);
            this._Domain       = GetDomainFromFullName(fullUserName);
            this._Password     = password;
            this._Identity     = (userToken == IntPtr.Zero) ? null : new WindowsIdentity(userToken);
            this._PathMap      = new Hashtable(StringComparer.OrdinalIgnoreCase);
            try
            {
                WindowsImpersonationContext context = (this._Identity != null) ? this._Identity.Impersonate() : null;
                try
                {
                    IRemoteWebConfigurationHostServer o = CreateRemoteObject(str3, this._Username, this._Domain, password);
                    try
                    {
                        str6 = o.GetFilePaths((int)level, str, site, locationSubPath);
                    }
                    finally
                    {
                        while (Marshal.ReleaseComObject(o) > 0)
                        {
                        }
                    }
                }
                finally
                {
                    if (context != null)
                    {
                        context.Undo();
                    }
                }
            }
            catch
            {
                throw;
            }
            if (str6 == null)
            {
                throw System.Web.Util.ExceptionUtil.UnexpectedError("RemoteWebConfigurationHost::InitForConfiguration");
            }
            string[] strArray = str6.Split(RemoteWebConfigurationHostServer.FilePathsSeparatorParams);
            if ((strArray.Length < 7) || (((strArray.Length - 5) % 2) != 0))
            {
                throw System.Web.Util.ExceptionUtil.UnexpectedError("RemoteWebConfigurationHost::InitForConfiguration");
            }
            for (int i = 0; i < strArray.Length; i++)
            {
                if (strArray[i].Length == 0)
                {
                    strArray[i] = null;
                }
            }
            string virtualPath = strArray[0];
            string str8        = strArray[1];
            string str9        = strArray[2];

            configPath         = strArray[3];
            locationConfigPath = strArray[4];
            this._ConfigPath   = configPath;
            WebConfigurationFileMap fileMap = new WebConfigurationFileMap();
            VirtualPath             path    = VirtualPath.CreateAbsoluteAllowNull(virtualPath);

            fileMap.Site = str9;
            for (int j = 5; j < strArray.Length; j += 2)
            {
                string key   = strArray[j];
                string str11 = strArray[j + 1];
                this._PathMap.Add(key, str11);
                if (WebConfigurationHost.IsMachineConfigPath(key))
                {
                    fileMap.MachineConfigFilename = str11;
                }
                else
                {
                    string virtualPathString;
                    bool   flag;
                    if (WebConfigurationHost.IsRootWebConfigPath(key))
                    {
                        virtualPathString = null;
                        flag = false;
                    }
                    else
                    {
                        VirtualPath path2;
                        string      str13;
                        WebConfigurationHost.GetSiteIDAndVPathFromConfigPath(key, out str13, out path2);
                        virtualPathString = VirtualPath.GetVirtualPathString(path2);
                        flag = path2 == path;
                    }
                    fileMap.VirtualDirectories.Add(virtualPathString, new VirtualDirectoryMapping(Path.GetDirectoryName(str11), flag));
                }
            }
            WebConfigurationHost host = new WebConfigurationHost();

            object[] hostInitParams = new object[6];
            hostInitParams[0] = true;
            hostInitParams[1] = new UserMapPath(fileMap, false);
            hostInitParams[3] = virtualPath;
            hostInitParams[4] = str8;
            hostInitParams[5] = str9;
            host.Init(root, hostInitParams);
            base.Host = host;
        }