Skip to content

Instantly share code, notes, and snippets.

@tonidy
Forked from mika76/Info.cshtml
Created October 20, 2021 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonidy/274f172b72e77e028ce7b4d003f705d4 to your computer and use it in GitHub Desktop.
Save tonidy/274f172b72e77e028ce7b4d003f705d4 to your computer and use it in GitHub Desktop.
phpinfo like page for .net core

phpinfo() like page for .NET Core

  • Make sure you have Razor Pages set up
  • Add a new Page /Pages/Info.cshtml
  • Add the below text to it
  • Navigate to http://..url../Info

That's it

I tried to make it match the branding on the Microsoft .NET Core page but there' not many colors to choose from...

@page
@{
Layout = "";
}
@using System.Linq;
@using System.Collections;
@using System.Reflection;
<html>
<head>
<title>netcoreinfo()</title>
<style>
body {
/*font-family:sans-serif;*/
font-family: Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif;
}
h2 {
color: #512bd4;
}
.h {
/* background-color:#9999cc; */
background-color: #7014e8;
background-image: url(https://dotnet.microsoft.com/static/images/redesign/home-hero-bg.svg);
font-weight: bold;
/*color:#000000;*/
color: #fff;
}
.h img {
float: right;
}
.m {
background-color: #ffffff;
text-align: right;
}
.m td {
border: 0 !important;
}
.m img {
float: right;
}
.e {
/*background-color:#ccccff;*/
background-color: #7014e8;
font-weight: bold;
/*color: #000000;*/
color: #ffffff;
width: 25%;
}
.v {
/* background-color:#cccccc;*/
background-color: #f4f4f4;
color: #000000;
}
table {
width: 80%;
border-collapse: collapse;
}
td,
th {
/*border: 1px solid #000000;*/
border: 1px solid #c8c8c8;
font-size: 75%;
vertical-align: baseline;
padding: 3px;
word-break: break-word;
}
.center {
text-align: center;
}
.center table {
margin-left: auto;
margin-right: auto;
text-align: left;
}
.center th {
text-align: center !important;
}
</style>
</head>
<body>
<div class="center">
<table>
<tbody>
<tr class="h">
<td>
<a href="https://dotnet.microsoft.com/">
<img src=" https://upload.wikimedia.org/wikipedia/commons/e/ee/.NET_Core_Logo.svg" height="50" />
</a>
<h1 class="p">.NET Core @Environment.Version</h1>
</td>
</tr>
</tbody>
</table>
<br />
<table>
<tbody>
<tr>
<td class="e">Environment OS Version</td>
<td class="v">@Environment.OSVersion</td>
</tr>
<tr>
<td class="e">OS Description</td>
<td class="v">@System.Runtime.InteropServices.RuntimeInformation.OSDescription</td>
</tr>
<tr>
<td class="e">OS Architecture</td>
<td class="v">@System.Runtime.InteropServices.RuntimeInformation.OSArchitecture</td>
</tr>
<tr>
<td class="e">Process Architecture</td>
<td class="v">@System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture</td>
</tr>
<tr>
<td class="e">Framework</td>
<td class="v">@System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription</td>
</tr>
<tr>
<td class="e">Argments</td>
<td class="v">@string.Join(" ", @Environment.GetCommandLineArgs())</td>
</tr>
</tbody>
</table>
<h2>Environment</h2>
<table>
<tbody>
<tr class="h">
<th>Variable</th>
<th>Value</th>
</tr>
@{
var env = Environment.GetEnvironmentVariables();
}
@foreach (string key in env.Keys.Cast<string>().OrderBy(k => k))
{
<tr>
<td class="e">@key</td>
<td class="v">@env[key]</td>
</tr>
}
</tbody>
</table>
<h2>HTTP Headers Information</h2>
<table>
<tbody>
<tr class="h">
<th colspan="2">HTTP Request Headers</th>
</tr>
@{
var reqHeaders = Request.Headers;
var resHeaders = Response.Headers;
}
@foreach (string key in reqHeaders.Keys.Cast<string>().OrderBy(k => k))
{
<tr>
<td class="e">@key</td>
<td class="v">@reqHeaders[key]</td>
</tr>
}
<tr class="h">
<th colspan="2">HTTP Response Headers</th>
</tr>
@foreach (string key in resHeaders.Keys.Cast<string>().OrderBy(k => k))
{
<tr>
<td class="e">@key</td>
<td class="v">@resHeaders[key]</td>
</tr>
}
</tbody>
</table>
@foreach (AssemblyName an in Assembly.GetExecutingAssembly().GetReferencedAssemblies())
{
Assembly asm = Assembly.Load(an.ToString());
Func<Type, string, string> AssInfo = (t, p) =>
{
var a = asm.GetCustomAttributes(t).SingleOrDefault();
if (a == null) return "";
var ppr = a.GetType().GetProperties().Where(pr => pr.Name == p).SingleOrDefault();
if (ppr == null) return "";
return (string)ppr.GetValue(a);
};
<h2>@AssInfo(typeof(AssemblyTitleAttribute), "Title")</h2>
@* <pre>@string.Join("\r\n",asm.GetCustomAttributes().Select(a=>a.ToString()));</pre> *@
<table>
<tbody>
<tr>
<td class="e">Title</td>
<td class="v">@AssInfo(typeof(AssemblyTitleAttribute), "Title")</td>
</tr>
<tr>
<td class="e">Copyright</td>
<td class="v">@AssInfo(typeof(AssemblyCopyrightAttribute), "Copyright")</td>
</tr>
<tr>
<td class="e">File Version</td>
<td class="v">@AssInfo(typeof(AssemblyFileVersionAttribute), "Version")</td>
</tr>
<tr>
<td class="e">Informational Version</td>
<td class="v">@AssInfo(typeof(AssemblyInformationalVersionAttribute), "InformationalVersion")</td>
</tr>
<tr>
<td class="e">Description</td>
<td class="v">@AssInfo(typeof(AssemblyDescriptionAttribute), "Description")</td>
</tr>
</tbody>
</table>
}
<br />
<br />
<table class="m">
<tr>
<td><img height="100"
src="//img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE2qVsJ?ver=3f74" /></td>
</tr>
</table>
</div>
</body>
<html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment