Inheritance: IInternalConfigHost
コード例 #1
0
        void IInternalConfigWebHost.GetSiteIDAndVPathFromConfigPath(string configPath, out string siteID, out string vpath)
        {
            VirtualPath virtualPath;

            WebConfigurationHost.GetSiteIDAndVPathFromConfigPath(configPath, out siteID, out virtualPath);
            vpath = VirtualPath.GetVirtualPathString(virtualPath);
        }
コード例 #2
0
        static void ConfigurationSaveHandler(_Configuration sender, ConfigurationSaveEventArgs args)
        {
            bool locked = false;

            try {
#if SYSTEMCORE_DEP
                sectionCacheLock.EnterWriteLock();
#endif
                locked = true;
                sectionCache.Clear();
            } finally {
#if SYSTEMCORE_DEP
                if (locked)
                {
                    sectionCacheLock.ExitWriteLock();
                }
#endif
            }

            lock (suppressAppReloadLock) {
                string rootConfigPath = WebConfigurationHost.GetWebConfigFileName(HttpRuntime.AppDomainAppPath);
                if (String.Compare(args.StreamPath, rootConfigPath, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    SuppressAppReload(args.Start);
                    if (args.Start)
                    {
                        HttpApplicationFactory.DisableWatcher(VirtualPathUtility.RemoveTrailingSlash(HttpRuntime.AppDomainAppPath), "?eb.?onfig");

                        lock (saveLocationsCacheLock) {
                            if (saveLocationsCache == null)
                            {
                                saveLocationsCache = new Dictionary <string, DateTime> (StringComparer.Ordinal);
                            }
                            if (saveLocationsCache.ContainsKey(rootConfigPath))
                            {
                                saveLocationsCache [rootConfigPath] = DateTime.Now;
                            }
                            else
                            {
                                saveLocationsCache.Add(rootConfigPath, DateTime.Now);
                            }

                            if (saveLocationsTimer == null)
                            {
                                saveLocationsTimer = new Timer(ReenableWatcherOnConfigLocation,
                                                               rootConfigPath,
                                                               SAVE_LOCATIONS_CHECK_INTERVAL,
                                                               SAVE_LOCATIONS_CHECK_INTERVAL);
                            }
                        }
                    }
                }
            }
        }
        public ApplicationSettingsConfigurationFileMap()
        {
            HttpContext ctx = HttpContext.Current;
            HttpRequest req = ctx != null ? ctx.Request : null;

            if (req != null)
            {
                MachineConfigFilename = WebConfigurationHost.GetWebConfigFileName(req.MapPath(WebConfigurationManager.FindWebConfig(req.CurrentExecutionFilePath)));
            }
            else
            {
                MachineConfigFilename = null;
            }
        }
コード例 #4
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));
        }
コード例 #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());
        }
コード例 #6
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));
        }
コード例 #7
0
 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;
             }
         }
     }
 }
 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;
             }
         }
     }
 }
コード例 #9
0
        //
        // 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.");
        }
コード例 #10
0
        internal static string FindWebConfig(string path)
        {
            if (String.IsNullOrEmpty(path))
            {
                return(path);
            }

            string dir;

            if (path [path.Length - 1] == '/')
            {
                dir = path;
            }
            else
            {
                dir = VirtualPathUtility.GetDirectory(path, false);
                if (dir == null)
                {
                    return(path);
                }
            }

            string curPath = configPaths [dir] as string;

            if (curPath != null)
            {
                return(curPath);
            }

            HttpContext ctx = HttpContext.Current;
            HttpRequest req = ctx != null ? ctx.Request : null;

            if (req == null)
            {
                return(path);
            }

            curPath = path;
            string rootPath = HttpRuntime.AppDomainAppVirtualPath;
            string physPath;

            while (String.Compare(curPath, rootPath, StringComparison.Ordinal) != 0)
            {
                physPath = MapPath(req, curPath);
                if (physPath == null)
                {
                    curPath = rootPath;
                    break;
                }

                if (WebConfigurationHost.GetWebConfigFileName(physPath) != null)
                {
                    break;
                }

                curPath = GetParentDir(rootPath, curPath);
                if (curPath == null || curPath == "~")
                {
                    curPath = rootPath;
                    break;
                }
            }

            configPaths [dir] = curPath;
            return(curPath);
        }
コード例 #11
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;
        }
コード例 #12
0
        internal static string FindWebConfig(string path, out bool inAnotherApp)
        {
            inAnotherApp = false;

            if (String.IsNullOrEmpty(path))
            {
                return(path);
            }

            if (HostingEnvironment.VirtualPathProvider != null)
            {
                if (HostingEnvironment.VirtualPathProvider.DirectoryExists(path))
                {
                    path = VirtualPathUtility.AppendTrailingSlash(path);
                }
            }


            string     rootPath = HttpRuntime.AppDomainAppVirtualPath;
            ConfigPath curPath;

            curPath = configPaths [path] as ConfigPath;
            if (curPath != null)
            {
                inAnotherApp = curPath.InAnotherApp;
                return(curPath.Path);
            }

            HttpContext ctx      = HttpContext.Current;
            HttpRequest req      = ctx != null ? ctx.Request : null;
            string      physPath = req != null?VirtualPathUtility.AppendTrailingSlash(MapPath (req, path)) : null;

            string appDomainPath = HttpRuntime.AppDomainAppPath;

            if (physPath != null && appDomainPath != null && !physPath.StartsWith(appDomainPath, StringComparison.Ordinal))
            {
                inAnotherApp = true;
            }

            string dir;

            if (inAnotherApp || path [path.Length - 1] == '/')
            {
                dir = path;
            }
            else
            {
                dir = VirtualPathUtility.GetDirectory(path, false);
                if (dir == null)
                {
                    return(path);
                }
            }

            curPath = configPaths [dir] as ConfigPath;
            if (curPath != null)
            {
                inAnotherApp = curPath.InAnotherApp;
                return(curPath.Path);
            }

            if (req == null)
            {
                return(path);
            }

            curPath = new ConfigPath(path, inAnotherApp);
            while (String.Compare(curPath.Path, rootPath, StringComparison.Ordinal) != 0)
            {
                physPath = MapPath(req, curPath.Path);
                if (physPath == null)
                {
                    curPath.Path = rootPath;
                    break;
                }

                if (WebConfigurationHost.GetWebConfigFileName(physPath) != null)
                {
                    break;
                }

                curPath.Path = GetParentDir(rootPath, curPath.Path);
                if (curPath.Path == null || curPath.Path == "~")
                {
                    curPath.Path = rootPath;
                    break;
                }
            }

            if (String.Compare(curPath.Path, path, StringComparison.Ordinal) != 0)
            {
                configPaths [path] = curPath;
            }
            else
            {
                configPaths [dir] = curPath;
            }

            return(curPath.Path);
        }
コード例 #13
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());
        }
コード例 #14
0
 /////////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////////
 public override void GetRestrictedPermissions(IInternalConfigRecord configRecord, out PermissionSet permissionSet, out bool isHostReady)
 {
     WebConfigurationHost.StaticGetRestrictedPermissions(configRecord, out permissionSet, out isHostReady);
 }
コード例 #15
0
 string IInternalConfigWebHost.GetConfigPathFromSiteIDAndVPath(string siteID, string vpath)
 {
     return(WebConfigurationHost.GetConfigPathFromSiteIDAndVPath(
                siteID, VirtualPath.CreateAbsoluteAllowNull(vpath)));
 }
コード例 #16
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;
        }
コード例 #17
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;
        }
 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;
 }
コード例 #19
0
        //
        // 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.");
        }