GetWebConfigFileName() private méthode

private GetWebConfigFileName ( dir dir ) : System
dir dir
Résultat System
Exemple #1
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;
            }
        }
Exemple #3
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);
        }
        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);
        }