Skip to content

Instantly share code, notes, and snippets.

@jballe
Created January 16, 2024 09:16
Show Gist options
  • Save jballe/23226d878934331efb9bdb47be21b210 to your computer and use it in GitHub Desktop.
Save jballe/23226d878934331efb9bdb47be21b210 to your computer and use it in GitHub Desktop.
ASP.Net show environment variables, headers, etc.
<%@ Page Language="C#" %>
<script runat="server">
private void RenderVariableCollection(string title, IDictionary<string, string> collection)
{
Response.Write("<tr><th colspan=\"2\" class=\"header\">" + title + "</th></tr>\n");
foreach (string key in collection.Keys.OrderBy(x => x))
{
Response.Write("<tr><th>" + key + "</th><td>" + collection[key] + " </td></tr>\n");
}
}
protected void RenderVars()
{
Response.Write("<table border=\"1\">");
var envs = Environment.GetEnvironmentVariables();
RenderVariableCollection("Env variables", envs.Keys.Cast<string>().ToDictionary(x => x, x => envs[x] as string));
RenderVariableCollection("AppSettings", ConfigurationManager.AppSettings.AllKeys.ToDictionary(x => x, x => ConfigurationManager.AppSettings[x]));
RenderVariableCollection("ConnectionStrings", ConfigurationManager.ConnectionStrings.Cast<ConnectionStringSettings>().ToDictionary(x => x.Name, x => x.ConnectionString));
RenderVariableCollection("HTTP Headers", Request.Headers.AllKeys.ToDictionary(x => x, x => Request.Headers[x]));
RenderVariableCollection("IIS Variables", Request.ServerVariables.AllKeys.ToDictionary(x => x, x => Request.ServerVariables[x]));
Response.Write("</table>");
}
</script><html>
<head>
<title>Variables - diagnostics</title>
<style>
body, th, td {
font-family: Verdana;
font-size: 10px;
}
table {
border-collapse: collapse;
}
th {
font-size: 10px;
text-align: left;
}
th.header {
background-color: lightseagreen;
font-size: 14px;
padding: 5px;
}
</style>
</head>
<body>
<% RenderVars(); %>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment