System.Web.Helpers.ServerInfo.EnvironmentVariables C# (CSharp) Method

EnvironmentVariables() static private method

static private EnvironmentVariables ( ) : string>.IDictionary
return string>.IDictionary
        internal static IDictionary<string, string> EnvironmentVariables()
        {
            // todo: extract well defined subset for special use?

            // use a case-insensitive dictionary since environment variables are case-insensitive.
            IDictionary<string, string> environmentVariablesResult = new SortedDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            IDictionary environmentVariables;

            // todo: better way to deal with security; query config for trust level?
            try
            {
                environmentVariables = Environment.GetEnvironmentVariables();
            }
            catch (SecurityException)
            {
                return environmentVariablesResult;
            }

            foreach (DictionaryEntry entry in environmentVariables)
            {
                environmentVariablesResult.Add(entry.Key.ToString(), InsertWhiteSpace(entry.Value.ToString()));
            }

            return environmentVariablesResult;
        }

Usage Example

Example #1
0
        public static HtmlString GetHtml()
        {
            StringBuilder sb = new StringBuilder(_Style);

            sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "<h1 class=\"server-info\">{0}</h1>",
                                        HttpUtility.HtmlEncode(HelpersResources.ServerInfo_Header)));

            var configuration = ServerInfo.Configuration();

            Debug.Assert((configuration != null) && (configuration.Count > 0));
            PrintInfoSection(sb, HttpUtility.HtmlEncode(HelpersResources.ServerInfo_ServerConfigTable), configuration);

            var serverVariables = ServerInfo.ServerVariables();

            Debug.Assert((serverVariables != null));
            PrintInfoSection(sb, HelpersResources.ServerInfo_ServerVars, serverVariables);

            var legacyCAS = ServerInfo.LegacyCAS();

            if (legacyCAS.Any())
            {
                PrintInfoSection(sb, HelpersResources.ServerInfo_LegacyCAS, legacyCAS);
            }

            // Info below is not available in medium trust.

            var httpRuntimeInfo = ServerInfo.HttpRuntimeInfo();

            Debug.Assert(httpRuntimeInfo != null);

            if (!httpRuntimeInfo.Any())
            {
                sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "<p class=\"server-info\">{0}</p>",
                                            HttpUtility.HtmlEncode(HelpersResources.ServerInfo_AdditionalInfo)));
                return(new HtmlString(sb.ToString()));
            }
            else
            {
                PrintInfoSection(sb, HelpersResources.ServerInfo_HttpRuntime, httpRuntimeInfo);

                var envVariables = ServerInfo.EnvironmentVariables();
                Debug.Assert(envVariables != null);
                PrintInfoSection(sb, HelpersResources.ServerInfo_EnvVars, envVariables);
            }

            return(new HtmlString(sb.ToString()));
        }