GetConfig() private method

private GetConfig ( string name ) : object
name string
return object
Beispiel #1
0
        internal static CustomErrors GetSettings(HttpContext context, bool canThrow)
        {
            CustomErrors ce = null;

            if (canThrow)
            {
                ce = (CustomErrors)context.GetConfig("system.web/customErrors");
            }
            else
            {
                ce = (CustomErrors)context.GetLKGConfig("system.web/customErrors");
            }

            if (ce == null)
            {
                if (_default == null)
                {
                    _default = new CustomErrors();
                }

                ce = _default;
            }

            return(ce);
        }
Beispiel #2
0
		internal static string GetScriptLocation(HttpContext context)
		{
			IDictionary dict = context.GetConfig("system.web/webControls")
			                    as IDictionary;
			string loc = null;
			if(dict != null)
			{
				loc = dict["clientScriptsLocation"] as string;
			}
			if(loc == null)
			{
				throw new HttpException("Missing_clientScriptsLocation");
			}
			if(loc.IndexOf("{0}") > 0)
			{
				//FIXME: Version Number of the ASP.Net should come into play.
				//Like if ASP 1.0 and 1.1 both are installed, the script
				// locations are in /aspnet_client/system_web/1_0_3705_0/
				// and /aspnet_client/system_web/1_1_4322/
				// (these entries are from my machine
				// So, first I should get this Version Info from somewhere
				loc = String.Format(loc, "system_web");
			}
			return loc;
		}
		static public CompilationConfiguration GetInstance (HttpContext context)
		{
			CompilationConfiguration config;
			if (context == null)
				context = HttpContext.Context;

			config = context.GetConfig ("system.web/compilation") as CompilationConfiguration;

			if (config == null)
				throw new Exception ("Configuration error.");

			return config;
		}
		static public HttpRuntimeConfig GetInstance (HttpContext context)
		{
			HttpRuntimeConfig config;
			if (context == null)
				context = HttpContext.Context;

			config = context.GetConfig ("system.web/httpRuntime") as HttpRuntimeConfig;

			if (config == null)
				throw new Exception ("Configuration error.");

			return config;
		}
		static public CompilationConfiguration GetInstance (HttpContext context)
		{
			CompilationConfiguration config;
			if (context == null)
				context = HttpContext.Current;

			if (context != null) {
				config = context.GetConfig ("system.web/compilation") as CompilationConfiguration;
				if (config == null)
					throw new Exception ("Configuration error.");
			} else {
				// empty config (as used in unit tests)
				config = new CompilationConfiguration (null);
			}

			return config;
		}
		bool RedirectCustomError (HttpContext context)
		{
			if (!context.IsCustomErrorEnabled)
				return false;

			CustomErrorsConfig config = null;
			try {
				config = (CustomErrorsConfig) context.GetConfig ("system.web/customErrors");
			} catch { }

			if (config == null) {
				if (context.ErrorPage != null)
					return context.Response.RedirectCustomError (context.ErrorPage);

				return false;
			}

			string redirect =  config [context.Response.StatusCode];
			if (redirect == null) {
				redirect = context.ErrorPage;
				if (redirect == null)
					redirect = config.DefaultRedirect;
			}

			if (redirect == null)
				return false;

			return context.Response.RedirectCustomError (redirect);
		}
        /// <summary>
        /// Finds the path for client files used be server controls.
        /// </summary>
        /// <param name="context">The context from which to get the configuration.</param>
        /// <returns>The path name.</returns>
        private static string FindCommonPath(HttpContext context)
        {
            // Look at the current configuration for the path
            if (context != null)
            {
                NameValueCollection table = (NameValueCollection)context.GetConfig(ConfigName);
                if (table != null)
                {
                    string path = (string)table[CommonFilesKey];
                    if (path != null)
                    {
                        return CleanupPath(path);
                    }
                }
            }

            // Return the default path with version number
            Assembly assembly = typeof(BaseRichControl).Assembly;
            Version version = assembly.GetName().Version;

            return DefaultCommonFilesRoot + version.Major.ToString() + "_" + version.Minor.ToString() + "/";
        }
            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();
                        }
                    }
                }
            }