void IConfigMapPath.ResolveSiteArgument(string siteArgument, out string siteName, out string siteID)
 {
     if ((string.IsNullOrEmpty(siteArgument) || StringUtil.EqualsIgnoreCase(siteArgument, "1")) || StringUtil.EqualsIgnoreCase(siteArgument, this._defaultSiteName))
     {
         siteName = this._defaultSiteName;
         siteID   = "1";
     }
     else
     {
         siteName = string.Empty;
         siteID   = string.Empty;
         bool flag = false;
         if (IISMapPath.IsSiteId(siteArgument))
         {
             flag = this.MBGetSiteNameFromSiteID(siteArgument, out siteName);
         }
         if (flag)
         {
             siteID = siteArgument;
         }
         else if (this.MBGetSiteIDFromSiteName(siteArgument, out siteID))
         {
             siteName = siteArgument;
         }
         else
         {
             siteName = siteArgument;
             siteID   = string.Empty;
         }
     }
 }
        internal static IConfigMapPath GetInstance()
        {
            IConfigMapPath instance      = IISMapPath.GetInstance();
            IConfigMapPath configMapPath = HostingEnvironment.ConfigMapPath;

            if ((configMapPath != null) && !(instance.GetType() == configMapPath.GetType()))
            {
                return(new HostingPreferredMapPath(instance, configMapPath));
            }
            return(instance);
        }
        void IConfigMapPath.ResolveSiteArgument(string siteArgument, out string siteName, out string siteID)
        {
            Debug.Trace("MapPath", "ProcHostMP.ResolveSiteArgument(" + siteArgument + ")\n");


            if (String.IsNullOrEmpty(siteArgument) ||
                StringUtil.EqualsIgnoreCase(siteArgument, ProcessHostConfigUtils.DEFAULT_SITE_ID_STRING) ||
                StringUtil.EqualsIgnoreCase(siteArgument, ProcessHostConfigUtils.GetSiteNameFromId(ProcessHostConfigUtils.DEFAULT_SITE_ID_UINT)))
            {
                siteName = ProcessHostConfigUtils.GetSiteNameFromId(ProcessHostConfigUtils.DEFAULT_SITE_ID_UINT);
                siteID   = ProcessHostConfigUtils.DEFAULT_SITE_ID_STRING;
            }
            else
            {
                siteName = String.Empty;
                siteID   = String.Empty;

                string resolvedName = null;
                if (IISMapPath.IsSiteId(siteArgument))
                {
                    uint id;

                    if (UInt32.TryParse(siteArgument, out id))
                    {
                        resolvedName = ProcessHostConfigUtils.GetSiteNameFromId(id);
                    }
                }
                // try to resolve the string
                else
                {
                    uint id = UnsafeIISMethods.MgdResolveSiteName(IntPtr.Zero, siteArgument);
                    if (id != 0)
                    {
                        siteID   = id.ToString(CultureInfo.InvariantCulture);
                        siteName = siteArgument;
                        return;
                    }
                }

                if (!String.IsNullOrEmpty(resolvedName))
                {
                    siteName = resolvedName;
                    siteID   = siteArgument;
                }
                else
                {
                    siteName = siteArgument;
                    siteID   = String.Empty;
                }
            }

            Debug.Assert(!String.IsNullOrEmpty(siteName), "!String.IsNullOrEmpty(siteName), siteArg=" + siteArgument);
        }
        internal static IConfigMapPath GetInstance()
        {
            IConfigMapPath iisConfigMapPath     = IISMapPath.GetInstance();
            IConfigMapPath hostingConfigMapPath = HostingEnvironment.ConfigMapPath;

            // Only delegate if the types implementing IConfigMapPath are different.
            if (hostingConfigMapPath == null || iisConfigMapPath.GetType() == hostingConfigMapPath.GetType())
            {
                return(iisConfigMapPath);
            }

            return(new HostingPreferredMapPath(iisConfigMapPath, hostingConfigMapPath));
        }
示例#5
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());
        }
 void IConfigMapPath.ResolveSiteArgument(string siteArgument, out string siteName, out string siteID)
 {
     if ((string.IsNullOrEmpty(siteArgument) || StringUtil.EqualsIgnoreCase(siteArgument, "1")) || StringUtil.EqualsIgnoreCase(siteArgument, this._nativeConfig.GetSiteNameFromId(1)))
     {
         siteName = this._nativeConfig.GetSiteNameFromId(1);
         siteID   = "1";
     }
     else
     {
         siteName = string.Empty;
         siteID   = string.Empty;
         string siteNameFromId = null;
         if (IISMapPath.IsSiteId(siteArgument))
         {
             uint num;
             if (uint.TryParse(siteArgument, out num))
             {
                 siteNameFromId = this._nativeConfig.GetSiteNameFromId(num);
             }
         }
         else
         {
             uint num2 = this._nativeConfig.MgdResolveSiteName(siteArgument);
             if (num2 != 0)
             {
                 siteID   = num2.ToString(CultureInfo.InvariantCulture);
                 siteName = siteArgument;
                 return;
             }
         }
         if (!string.IsNullOrEmpty(siteNameFromId))
         {
             siteName = siteNameFromId;
             siteID   = siteArgument;
         }
         else
         {
             siteName = siteArgument;
             siteID   = string.Empty;
         }
     }
 }
 void IConfigMapPath.ResolveSiteArgument(string siteArgument, out string siteName, out string siteID)
 {
     if ((string.IsNullOrEmpty(siteArgument) || StringUtil.EqualsIgnoreCase(siteArgument, "1")) || StringUtil.EqualsIgnoreCase(siteArgument, ProcessHostConfigUtils.GetSiteNameFromId(1)))
     {
         siteName = ProcessHostConfigUtils.GetSiteNameFromId(1);
         siteID   = "1";
     }
     else
     {
         siteName = string.Empty;
         siteID   = string.Empty;
         string siteNameFromId = null;
         if (IISMapPath.IsSiteId(siteArgument))
         {
             uint num;
             if (uint.TryParse(siteArgument, out num))
             {
                 siteNameFromId = ProcessHostConfigUtils.GetSiteNameFromId(num);
             }
         }
         else
         {
             uint num2 = UnsafeIISMethods.MgdResolveSiteName(IntPtr.Zero, siteArgument);
             if (num2 != 0)
             {
                 siteID   = num2.ToString(CultureInfo.InvariantCulture);
                 siteName = siteArgument;
                 return;
             }
         }
         if (!string.IsNullOrEmpty(siteNameFromId))
         {
             siteName = siteNameFromId;
             siteID   = siteArgument;
         }
         else
         {
             siteName = siteArgument;
             siteID   = string.Empty;
         }
     }
 }
示例#8
0
 private void ChooseAndInitConfigMapPath(bool useConfigMapPath, IConfigMapPath configMapPath, ConfigurationFileMap fileMap)
 {
     if (useConfigMapPath)
     {
         this._configMapPath = configMapPath;
     }
     else if (fileMap != null)
     {
         this._configMapPath = new UserMapPath(fileMap);
     }
     else if (HostingEnvironment.IsHosted)
     {
         this._configMapPath = HostingPreferredMapPath.GetInstance();
     }
     else
     {
         this._configMapPath = IISMapPath.GetInstance();
     }
     this._configMapPath2 = this._configMapPath as IConfigMapPath2;
 }
        void IConfigMapPath.ResolveSiteArgument(string siteArgument, out string siteName, out string siteID)
        {
            if (String.IsNullOrEmpty(siteArgument) ||
                StringUtil.EqualsIgnoreCase(siteArgument, DEFAULT_SITEID) ||
                StringUtil.EqualsIgnoreCase(siteArgument, _defaultSiteName))
            {
                siteName = _defaultSiteName;
                siteID   = DEFAULT_SITEID;
            }
            else
            {
                siteName = String.Empty;
                siteID   = String.Empty;

                bool found = false;
                if (IISMapPath.IsSiteId(siteArgument))
                {
                    found = MBGetSiteNameFromSiteID(siteArgument, out siteName);
                }

                if (found)
                {
                    siteID = siteArgument;
                }
                else
                {
                    found = MBGetSiteIDFromSiteName(siteArgument, out siteID);
                    if (found)
                    {
                        siteName = siteArgument;
                    }
                    else
                    {
                        siteName = siteArgument;
                        siteID   = String.Empty;
                    }
                }
            }
        }
 internal static void EnsureInit(IConfigMapPath configMapPath, bool listenToFileChanges, bool initComplete)
 {
     if (!s_inited)
     {
         lock (s_initLock)
         {
             if (!s_inited)
             {
                 s_initComplete = initComplete;
                 if (configMapPath == null)
                 {
                     configMapPath = IISMapPath.GetInstance();
                 }
                 s_configMapPath = configMapPath;
                 s_configSystem  = (IConfigSystem)Activator.CreateInstance(Type.GetType("System.Configuration.Internal.ConfigSystem, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", true), true);
                 object[] hostInitParams = new object[6];
                 hostInitParams[0] = true;
                 hostInitParams[1] = s_configMapPath;
                 hostInitParams[3] = HostingEnvironment.ApplicationVirtualPath;
                 hostInitParams[4] = HostingEnvironment.SiteNameNoDemand;
                 hostInitParams[5] = HostingEnvironment.SiteID;
                 s_configSystem.Init(typeof(WebConfigurationHost), hostInitParams);
                 s_configRoot = s_configSystem.Root;
                 s_configHost = (WebConfigurationHost)s_configSystem.Host;
                 HttpConfigurationSystem internalConfigSystem = new HttpConfigurationSystem();
                 if (listenToFileChanges)
                 {
                     s_configRoot.ConfigChanged += new InternalConfigEventHandler(internalConfigSystem.OnConfigurationChanged);
                 }
                 s_configSettingsFactory = (IInternalConfigSettingsFactory)Activator.CreateInstance(Type.GetType("System.Configuration.Internal.InternalConfigSettingsFactory, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", true), true);
                 s_configSettingsFactory.SetConfigurationSystem(internalConfigSystem, initComplete);
                 s_httpConfigSystem = internalConfigSystem;
                 s_inited           = true;
             }
         }
     }
 }
示例#11
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());
        }
        //
        // Set this configuration system to the default for requests ConfigurationManager.GetSection
        //
        static internal void EnsureInit(IConfigMapPath configMapPath, bool listenToFileChanges, bool initComplete)
        {
            if (!s_inited)
            {
                lock (s_initLock) {
                    if (!s_inited)
                    {
                        s_initComplete = initComplete;

                        // Use the IIS map path if one is not explicitly provided
                        if (configMapPath == null)
                        {
                            configMapPath = IISMapPath.GetInstance();
                        }

                        s_configMapPath = configMapPath;

                        Type typeConfigSystem = Type.GetType(ConfigSystemTypeString, true);
                        s_configSystem = (IConfigSystem)Activator.CreateInstance(typeConfigSystem, true);
                        s_configSystem.Init(
                            typeof(WebConfigurationHost),                   // The config host we'll create and use
                            // The remaining parameters are passed to the config host:
                            true,                                           // Use the supplied configMapPath
                            s_configMapPath,                                // the configMapPath to use
                            null,                                           // ConfigurationFileMap
                            HostingEnvironment.ApplicationVirtualPath,      // app path
                            HostingEnvironment.SiteNameNoDemand,            // app site name
                            HostingEnvironment.SiteID);                     // app site ID

                        s_configRoot = s_configSystem.Root;
                        s_configHost = (WebConfigurationHost)s_configSystem.Host;

                        // Register for config changed notifications
                        HttpConfigurationSystem configSystem = new HttpConfigurationSystem();

                        if (listenToFileChanges)
                        {
                            s_configRoot.ConfigChanged += new InternalConfigEventHandler(configSystem.OnConfigurationChanged);
                        }

                        // Set the configSystem into the ConfigurationManager class.
                        // Please note that factory.SetConfigurationSystem will end up calling
                        // ConfigurationManager.SetConfigurationSystem, which is an internal static method
                        // in System.Configuration.dll.  If we want to call that here, we have to use
                        // reflection and that's what we want to avoid.
                        Type typeFactory = Type.GetType(InternalConfigSettingsFactoryTypeString, true);
                        s_configSettingsFactory = (IInternalConfigSettingsFactory)Activator.CreateInstance(typeFactory, true);
                        s_configSettingsFactory.SetConfigurationSystem(configSystem, initComplete);

                        // The system has been successfully set, so mark that we should use it.
                        s_httpConfigSystem = configSystem;

                        // Mark as having completed initialization after s_httpConfigSystem has been set.
                        // s_inited is coordinated with s_httpConfigSystem in UseHttpConfigurationSystem.
                        s_inited = true;
                    }
                }
            }

            Debug.Assert(s_httpConfigSystem != null, "s_httpConfigSystem != null - The appdomain is using the client configuration system.");
        }