示例#1
0
        static HttpRuntime()
        {
#if !TARGET_J2EE
            firstRun = true;

            try {
                WebConfigurationManager.Init();
#if MONOWEB_DEP
                SettingsMappingManager.Init();
#endif
                runtime_section = (HttpRuntimeSection)WebConfigurationManager.GetSection("system.web/httpRuntime");
            } catch (Exception ex) {
                initialException = ex;
            }

            // The classes in whose constructors exceptions may be thrown, should be handled the same way QueueManager
            // and TraceManager are below. The constructors themselves MUST NOT throw any exceptions - we MUST be sure
            // the objects are created here. The exceptions will be dealt with below, in RealProcessRequest.
            queue_manager = new QueueManager();
            if (queue_manager.HasException)
            {
                if (initialException == null)
                {
                    initialException = queue_manager.InitialException;
                }
                else
                {
                    Console.Error.WriteLine("Exception during QueueManager initialization:");
                    Console.Error.WriteLine(queue_manager.InitialException);
                }
            }

            trace_manager = new TraceManager();
            if (trace_manager.HasException)
            {
                if (initialException == null)
                {
                    initialException = trace_manager.InitialException;
                }
                else
                {
                    Console.Error.WriteLine("Exception during TraceManager initialization:");
                    Console.Error.WriteLine(trace_manager.InitialException);
                }
            }

            registeredAssemblies = new SplitOrderedList <string, string> (StringComparer.Ordinal);
            cache         = new Cache();
            internalCache = new Cache();
            internalCache.DependencyCache = internalCache;
#endif
            do_RealProcessRequest = new WaitCallback(state => {
                try {
                    RealProcessRequest(state);
                } catch {}
            });
            end_of_send_cb = new HttpWorkerRequest.EndOfSendNotification(EndOfSend);
        }
示例#2
0
        internal static object GetSection(string sectionName, string path, HttpContext context)
        {
            if (String.IsNullOrEmpty(sectionName))
            {
                return(null);
            }

            _Configuration c            = OpenWebConfiguration(path, null, null, null, null, null, false);
            string         configPath   = c.ConfigPath;
            int            baseCacheKey = 0;
            int            cacheKey;
            bool           pathPresent  = !String.IsNullOrEmpty(path);
            string         locationPath = null;
            bool           locked       = false;

            if (pathPresent)
            {
                locationPath = "location_" + path;
            }

            baseCacheKey = sectionName.GetHashCode();
            if (configPath != null)
            {
                baseCacheKey ^= configPath.GetHashCode();
            }

            try {
#if SYSTEMCORE_DEP
                sectionCacheLock.EnterReadLock();
#endif
                locked = true;

                object o;
                if (pathPresent)
                {
                    cacheKey = baseCacheKey ^ locationPath.GetHashCode();
                    if (sectionCache.TryGetValue(cacheKey, out o))
                    {
                        return(o);
                    }

                    cacheKey = baseCacheKey ^ path.GetHashCode();
                    if (sectionCache.TryGetValue(cacheKey, out o))
                    {
                        return(o);
                    }
                }

                if (sectionCache.TryGetValue(baseCacheKey, out o))
                {
                    return(o);
                }
            } finally {
#if SYSTEMCORE_DEP
                if (locked)
                {
                    sectionCacheLock.ExitReadLock();
                }
#endif
            }

            string cachePath = null;
            if (pathPresent)
            {
                string relPath;

                if (VirtualPathUtility.IsRooted(path))
                {
                    if (path [0] == '~')
                    {
                        relPath = path.Substring(2);
                    }
                    else if (path [0] == '/')
                    {
                        relPath = path.Substring(1);
                    }
                    else
                    {
                        relPath = path;
                    }
                }
                else
                {
                    relPath = path;
                }

                _Configuration cnew;

                HttpRequest req = context != null ? context.Request : null;
                if (req != null)
                {
                    string vdir = VirtualPathUtility.GetDirectory(req.Path);
                    if (vdir != null)
                    {
                        vdir = vdir.TrimEnd(pathTrimChars);
                        if (String.Compare(c.ConfigPath, vdir, StringComparison.Ordinal) != 0 && LookUpLocation(vdir.Trim(pathTrimChars), ref c))
                        {
                            cachePath = path;
                        }
                    }
                }

                if (LookUpLocation(relPath, ref c))
                {
                    cachePath = locationPath;
                }
                else
                {
                    cachePath = path;
                }
            }

            ConfigurationSection section = c.GetSection(sectionName);
            if (section == null)
            {
                return(null);
            }

#if TARGET_J2EE
            object value = get_runtime_object.Invoke(section, new object [0]);
            if (String.CompareOrdinal("appSettings", sectionName) == 0)
            {
                NameValueCollection collection;
                collection = new KeyValueMergedCollection(HttpContext.Current, (NameValueCollection)value);
                value      = collection;
            }
#else
#if MONOWEB_DEP
            object value = SettingsMappingManager.MapSection(get_runtime_object.Invoke(section, new object [0]));
#else
            object value = null;
#endif
#endif
            if (cachePath != null)
            {
                cacheKey = baseCacheKey ^ cachePath.GetHashCode();
            }
            else
            {
                cacheKey = baseCacheKey;
            }

            AddSectionToCache(cacheKey, value);
            return(value);
        }
示例#3
0
        internal static object GetSection(string sectionName, string path, HttpContext context)
        {
            if (String.IsNullOrEmpty(sectionName))
            {
                return(null);
            }

            _Configuration c            = OpenWebConfiguration(path, null, null, null, null, null, false);
            string         configPath   = c.ConfigPath;
            int            baseCacheKey = 0;
            int            cacheKey;
            bool           pathPresent  = !String.IsNullOrEmpty(path);
            string         locationPath = null;

            if (pathPresent)
            {
                locationPath = "location_" + path;
            }

            baseCacheKey = sectionName.GetHashCode();
            if (configPath != null)
            {
                baseCacheKey ^= configPath.GetHashCode();
            }

            try {
                sectionCacheLock.EnterWriteLock();

                object o;
                if (pathPresent)
                {
                    cacheKey = baseCacheKey ^ locationPath.GetHashCode();
                    if (sectionCache.TryGetValue(cacheKey, out o))
                    {
                        return(o);
                    }

                    cacheKey = baseCacheKey ^ path.GetHashCode();
                    if (sectionCache.TryGetValue(cacheKey, out o))
                    {
                        return(o);
                    }
                }

                if (sectionCache.TryGetValue(baseCacheKey, out o))
                {
                    return(o);
                }
            } finally {
                sectionCacheLock.ExitWriteLock();
            }

            string cachePath = null;

            if (pathPresent)
            {
                string relPath;

                if (VirtualPathUtility.IsRooted(path))
                {
                    if (path [0] == '~')
                    {
                        relPath = path.Length > 1 ? path.Substring(2) : String.Empty;
                    }
                    else if (path [0] == '/')
                    {
                        relPath = path.Substring(1);
                    }
                    else
                    {
                        relPath = path;
                    }
                }
                else
                {
                    relPath = path;
                }

                HttpRequest req = context != null ? context.Request : null;
                if (req != null)
                {
                    string vdir = VirtualPathUtility.GetDirectory(req.PathNoValidation);
                    if (vdir != null)
                    {
                        vdir = vdir.TrimEnd(pathTrimChars);
                        if (String.Compare(c.ConfigPath, vdir, StringComparison.Ordinal) != 0 && LookUpLocation(vdir.Trim(pathTrimChars), ref c))
                        {
                            cachePath = path;
                        }
                    }
                }

                if (LookUpLocation(relPath, ref c))
                {
                    cachePath = locationPath;
                }
                else
                {
                    cachePath = path;
                }
            }

            ConfigurationSection section;

            lock (getSectionLock) {
                section = c.GetSection(sectionName);
            }
            if (section == null)
            {
                return(null);
            }

            object value = SettingsMappingManager.MapSection(section.GetRuntimeObject());

            if (cachePath != null)
            {
                cacheKey = baseCacheKey ^ cachePath.GetHashCode();
            }
            else
            {
                cacheKey = baseCacheKey;
            }

            AddSectionToCache(cacheKey, value);
            return(value);
        }
示例#4
0
        static HttpRuntime()
        {
            PlatformID pid = Environment.OSVersion.Platform;

            runningOnWindows = ((int)pid != 128
#if NET_2_0
                                && pid != PlatformID.Unix && pid != PlatformID.MacOSX
#endif
                                );

            if (runningOnWindows)
            {
                caseInsensitive = true;
                if (AppDomainAppPath != null)
                {
                    isunc = new Uri(AppDomainAppPath).IsUnc;
                }
            }
            else
            {
                string mono_iomap = Environment.GetEnvironmentVariable("MONO_IOMAP");
                if (mono_iomap != null)
                {
                    if (mono_iomap == "all")
                    {
                        caseInsensitive = true;
                    }
                    else
                    {
                        string[] parts = mono_iomap.Split(':');
                        foreach (string p in parts)
                        {
                            if (p == "all" || p == "case")
                            {
                                caseInsensitive = true;
                                break;
                            }
                        }
                    }
                }
            }

            Type monoRuntime = Type.GetType("Mono.Runtime", false);
            monoVersion = null;
            if (monoRuntime != null)
            {
                MethodInfo mi = monoRuntime.GetMethod("GetDisplayName", BindingFlags.Static | BindingFlags.NonPublic);
                if (mi != null)
                {
                    monoVersion = mi.Invoke(null, new object [0]) as string;
                }
            }

            if (monoVersion == null)
            {
                monoVersion = Environment.Version.ToString();
            }

#if !TARGET_J2EE
            firstRun = true;
#if NET_2_0
            try {
                WebConfigurationManager.Init();
#if MONOWEB_DEP
                SettingsMappingManager.Init();
#endif
            } catch (Exception ex) {
                initialException = ex;
            }
#endif

            // The classes in whose constructors exceptions may be thrown, should be handled the same way QueueManager
            // and TraceManager are below. The constructors themselves MUST NOT throw any exceptions - we MUST be sure
            // the objects are created here. The exceptions will be dealt with below, in RealProcessRequest.
            queue_manager = new QueueManager();
            if (queue_manager.HasException)
            {
                initialException = queue_manager.InitialException;
            }

            trace_manager = new TraceManager();
            if (trace_manager.HasException)
            {
                initialException = trace_manager.InitialException;
            }

            cache         = new Cache();
            internalCache = new Cache();
            internalCache.DependencyCache = cache;
#endif
            do_RealProcessRequest = new WaitCallback(RealProcessRequest);
            end_of_send_cb        = new HttpWorkerRequest.EndOfSendNotification(EndOfSend);
        }
示例#5
0
        internal static object GetSection(string sectionName, string path, HttpContext context)
        {
            // FindWebConfig must not be used here with its result being passed to
            // OpenWebConfiguration below. The reason is that if we have a request for
            // ~/somepath/, but FindWebConfig returns ~/ and the ~/web.config contains
            // <location path="somepath"> then OpenWebConfiguration will NOT return the
            // contents of <location>, thus leading to bugs (ignored authorization
            // section for instance)
            string config_vdir = FindWebConfig(path);

            if (String.IsNullOrEmpty(config_vdir))
            {
                config_vdir = "/";
            }

            int    sectionCacheKey = GetSectionCacheKey(sectionName, config_vdir);
            object cachedSection;
            bool   locked = false;

            try {
#if SYSTEMCORE_DEP
                sectionCacheLock.EnterReadLock();
#endif
                locked = true;

                if (sectionCache.TryGetValue(sectionCacheKey, out cachedSection) && cachedSection != null)
                {
                    return(cachedSection);
                }
            } finally {
#if SYSTEMCORE_DEP
                if (locked)
                {
                    sectionCacheLock.ExitReadLock();
                }
#endif
            }

            HttpRequest    req = context != null ? context.Request : null;
            _Configuration c   = OpenWebConfiguration(path,                                                           /* path */
                                                      null,                                                           /* site */
                                                      req != null ? VirtualPathUtility.GetDirectory(req.Path) : null, /* locationSubPath */
                                                      null,                                                           /* server */
                                                      null,                                                           /* userName */
                                                      null,                                                           /* password */
                                                      false /* path from FindWebConfig */);
            ConfigurationSection section = c.GetSection(sectionName);
            if (section == null)
            {
                return(null);
            }

#if TARGET_J2EE
            object value = get_runtime_object.Invoke(section, new object [0]);
            if (String.CompareOrdinal("appSettings", sectionName) == 0)
            {
                NameValueCollection collection;
                collection = new KeyValueMergedCollection(HttpContext.Current, (NameValueCollection)value);
                value      = collection;
            }

            AddSectionToCache(sectionCacheKey, value);
            return(value);
#else
#if MONOWEB_DEP
            object value = SettingsMappingManager.MapSection(get_runtime_object.Invoke(section, new object [0]));
#else
            object value = null;
#endif
            AddSectionToCache(sectionCacheKey, value);
            return(value);
#endif
        }