GetAppConfig() private method

private GetAppConfig ( string name ) : object
name string
return object
Beispiel #1
0
        static BaseResponseHeader()
        {
#if NET_2_0
            HttpRuntimeSection section = WebConfigurationManager.GetWebApplicationSection("system.web/httpRuntime") as HttpRuntimeSection;
#else
            HttpRuntimeConfig section = HttpContext.GetAppConfig("system.web/httpRuntime") as HttpRuntimeConfig;
#endif
            headerCheckingEnabled = section == null || section.EnableHeaderChecking;
        }
Beispiel #2
0
        public string ApplyAppPathModifier(string virtualPath)
        {
            if (virtualPath == null)
            {
                return(null);
            }

            if (virtualPath.Length == 0)
            {
                return(context.Request.RootVirtualDir);
            }

            if (UrlUtils.IsRelativeUrl(virtualPath))
            {
                virtualPath = UrlUtils.Combine(context.Request.RootVirtualDir, virtualPath);
            }
            else if (UrlUtils.IsRooted(virtualPath))
            {
                virtualPath = UrlUtils.Canonic(virtualPath);
            }

            bool cookieless = false;

#if NET_2_0
            SessionStateSection config = WebConfigurationManager.GetWebApplicationSection("system.web/sessionState") as SessionStateSection;
            cookieless = SessionStateModule.IsCookieLess(context, config);
#else
            SessionConfig config = HttpContext.GetAppConfig("system.web/sessionState") as SessionConfig;
            cookieless = config.CookieLess;
#endif
            if (!cookieless)
            {
                return(virtualPath);
            }

            if (app_path_mod != null && virtualPath.IndexOf(app_path_mod) < 0)
            {
                if (UrlUtils.HasSessionId(virtualPath))
                {
                    virtualPath = UrlUtils.RemoveSessionId(VirtualPathUtility.GetDirectory(virtualPath), virtualPath);
                }
                return(UrlUtils.InsertSessionId(app_path_mod, virtualPath));
            }

            return(virtualPath);
        }
Beispiel #3
0
        public QueueManager()
        {
            Exception ex = null;

            try {
#if NET_2_0
                HttpRuntimeSection config;

                config = (HttpRuntimeSection)WebConfigurationManager.GetWebApplicationSection("system.web/httpRuntime");
#else
                HttpRuntimeConfig config;

                config = (HttpRuntimeConfig)HttpContext.GetAppConfig("system.web/httpRuntime");
#endif
                minFree      = config.MinFreeThreads;
                minLocalFree = config.MinLocalRequestFreeThreads;
                queueLimit   = config.AppRequestQueueLimit;
            } catch (Exception e) {
                ex = e;
            }

            try {
                queue = new Queue(queueLimit);
            } catch (Exception e) {
                if (ex == null)
                {
                    initialException = e;
                }
                else
                {
                    StringBuilder sb = new StringBuilder("Several exceptions occurred:\n");
                    sb.AppendFormat("--- Exception Q1:\n{0}\n", ex.ToString());
                    sb.AppendFormat("--- Exception Q2:\n{0}\n", e.ToString());
                    initialException = new Exception(sb.ToString());
                }
            }

            if (initialException == null && ex != null)
            {
                initialException = ex;
            }

            requestsQueuedCounter          = new PerformanceCounter("ASP.NET", "Requests Queued");
            requestsQueuedCounter.RawValue = 0;
        }
Beispiel #4
0
        void Execute(string path, TextWriter writer, bool preserveForm, bool isTransfer)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            if (path.IndexOf(':') != -1)
            {
                throw new ArgumentException("Invalid path.");
            }

            string queryString = null;
            int    qmark       = path.IndexOf('?');

            if (qmark != -1)
            {
                queryString = path.Substring(qmark + 1);
                path        = path.Substring(0, qmark);
            }

            string exePath    = UrlUtils.Combine(context.Request.BaseVirtualDir, path);
            bool   cookieless = false;

#if NET_2_0
            SessionStateSection config = WebConfigurationManager.GetWebApplicationSection("system.web/sessionState") as SessionStateSection;
            cookieless = SessionStateModule.IsCookieLess(context, config);
#else
            SessionConfig config = HttpContext.GetAppConfig("system.web/sessionState") as SessionConfig;
            cookieless = config.CookieLess;
#endif
            if (cookieless)
            {
                exePath = UrlUtils.RemoveSessionId(VirtualPathUtility.GetDirectory(exePath), exePath);
            }

            IHttpHandler handler = context.ApplicationInstance.GetHandler(context, exePath, true);
            Execute(handler, writer, preserveForm, exePath, queryString, isTransfer, true);
        }
Beispiel #5
0
        public TraceManager()
        {
            try {
#if NET_2_0
                mode = TraceMode.SortByTime;
                TraceSection config = WebConfigurationManager.GetWebApplicationSection("system.web/trace") as TraceSection;
                if (config == null)
                {
                    config = new TraceSection();
                }
#else
                TraceConfig config = (TraceConfig)HttpContext.GetAppConfig(traceConfigPath);
#endif

                if (config == null)
                {
                    return;
                }

                enabled     = config.Enabled;
                local_only  = config.LocalOnly;
                page_output = config.PageOutput;
#if NET_2_0
                if (config.TraceMode == TraceDisplayMode.SortByTime)
                {
                    mode = TraceMode.SortByTime;
                }
                else
                {
                    mode = TraceMode.SortByCategory;
                }
#else
                mode = config.TraceMode;
#endif
                request_limit = config.RequestLimit;
            } catch (Exception ex) {
                initialException = ex;
            }
        }
            private void Init(bool appLevel, bool throwOnError)
            {
                if (_configKnown)
                {
                    return;
                }

                lock (this) {
                    if (_configKnown)
                    {
                        return;
                    }

                    if (HttpRuntime.ConfigInited)
                    {
                        IdentityConfig settings = null;

                        IntPtr tokenToReadConfig = IntPtr.Zero;

                        if (_context != null && HttpRuntime.IsOnUNCShareInternal && !_inProgress)
                        {
                            // when reading config on UNC share we have to impersonate around it
                            // note: we are getting config here to figure out the impersonation mode
                            tokenToReadConfig = _context._wr.GetUserToken();
                            UnsafeNativeMethods.SetThreadToken(IntPtr.Zero, tokenToReadConfig);
                        }

                        try {
                            try {
                                using (new HttpContextWrapper(_context)) { // getting config might require current context
                                    if (appLevel || _context == null)
                                    {
                                        if (s_appIdentityConfig != null)
                                        {
                                            settings = s_appIdentityConfig;
                                        }
                                        else
                                        {
                                            settings            = (IdentityConfig)HttpContext.GetAppConfig("system.web/identity");
                                            s_appIdentityConfig = settings;
                                        }
                                    }
                                    else
                                    {
                                        settings = (IdentityConfig)_context.GetConfig("system.web/identity");
                                    }
                                }
                            }
                            catch {
                                if (throwOnError)
                                {
                                    throw;
                                }
                            }
                            finally {
                                if (tokenToReadConfig != IntPtr.Zero)
                                {
                                    UnsafeNativeMethods.RevertToSelf();
                                }
                            }
                        }
                        catch { // Protect against exception filters
                            throw;
                        }


                        if (settings != null)
                        {
                            if (settings.EnableImpersonation)
                            {
                                if (settings.ImpersonateToken != IntPtr.Zero)
                                {
                                    _mode  = ImpersonationMode.Application;
                                    _token = settings.ImpersonateToken;
                                }
                                else if (_context != null)
                                {
                                    _mode  = ImpersonationMode.Client;
                                    _token = _context._wr.GetUserToken();
                                }
                            }
                            else
                            {
                                _mode  = ImpersonationMode.None;
                                _token = IntPtr.Zero;
                            }
                        }

                        // don't remember app level setting with context
                        if (!appLevel)
                        {
                            _configKnown = true;
                        }
                    }

                    // UNC impersonation overrides everything but Application credentials
                    // it is in effect event before config system gets initialized
                    if (_context != null && HttpRuntime.IsOnUNCShareInternal && _mode != ImpersonationMode.Application)
                    {
                        _mode = ImpersonationMode.UNC;
                        if (_token == IntPtr.Zero)
                        {
                            _token = _context._wr.GetUserToken();
                        }
                    }
                }
            }
Beispiel #7
0
        void MakeInputStream()
        {
            if (worker_request == null)
            {
                throw new HttpException("No HttpWorkerRequest");
            }

            // consider for perf:
            //    return ((ServletWorkerRequest)worker_request).InputStream();

            //
            // Use an unmanaged memory block as this might be a large
            // upload
            //
            int content_length = ContentLength;

#if NET_2_0
            HttpRuntimeSection config = (HttpRuntimeSection)WebConfigurationManager.GetSection("system.web/httpRuntime");
#else
            HttpRuntimeConfig config = (HttpRuntimeConfig)HttpContext.GetAppConfig("system.web/httpRuntime");
#endif
            if (content_length > (config.MaxRequestLength * 1024))
            {
                throw new HttpException("File exceeds httpRuntime limit");
            }

            byte[] content = new byte[content_length];
            if (content == null)
            {
                throw new HttpException(String.Format("Not enough memory to allocate {0} bytes", content_length));
            }

            int     total;
            byte [] buffer;
            buffer = worker_request.GetPreloadedEntityBody();
            if (buffer != null)
            {
                total = buffer.Length;
                if (content_length > 0)
                {
                    total = Math.Min(content_length, total);
                }
                Array.Copy(buffer, content, total);
            }
            else
            {
                total = 0;
            }

            buffer = new byte [INPUT_BUFFER_SIZE];
            while (total < content_length)
            {
                int n;
                n = worker_request.ReadEntityBody(buffer, Math.Min(content_length - total, INPUT_BUFFER_SIZE));
                if (n <= 0)
                {
                    break;
                }
                Array.Copy(buffer, 0, content, total, n);
                total += n;
            }
            if (total < content_length)
            {
                throw new HttpException(411, "The uploaded file is incomplete");
            }

            input_stream = new MemoryStream(content, 0, content.Length, false, true);

            DoFilter(buffer);
        }