Skip to content

Instantly share code, notes, and snippets.

@mika76
Last active October 20, 2021 16:49
Show Gist options
  • Save mika76/84df6985535c54d9c4a7adffb43e53eb to your computer and use it in GitHub Desktop.
Save mika76/84df6985535c54d9c4a7adffb43e53eb 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>
@andersbp
Copy link

Hi

Thanks for a good work!

When I try to run your application, my webserver give me the following error:
"An error occurred during the compilation of a resource required to service this request. Please review the following specific error details
and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'page' does not exist in the current context
Source Error:
Line 1: @page
Line 2: @{
Line 3: Layout = "";".
What is wrong here?

Via the web.config-file I have set the ASP.NET version to 2.0, since my webserver come up and tell me that I should do that.

Thanks in advance.

Regards,
Anders.

@mika76
Copy link
Author

mika76 commented Dec 18, 2020

@andersbp This is for asp.net core pages - you can see here how to set em up: https://docs.microsoft.com/en-us/aspnet/core/razor-pages/?view=aspnetcore-5.0&tabs=visual-studio

@andersbp
Copy link

@mika76
Thanks for the answer.

It is understand correct that I should unzip your project, and after that create/uploadd the project via Visuel Studio?

At the time I write you I first upload your project via FTP, and next of that login to my server via IES Manager, and convert the folder to an application.

Regards,
Anders

@mika76
Copy link
Author

mika76 commented Dec 18, 2020

Hi @andersbp This isn't really a whole project, just a file to put into an existing project. Maybe this tutorial might help to get you going: https://www.youtube.com/watch?v=68towqYcQlY

@andersbp
Copy link

@mika76

Thanks for your answer.

What type of .net core and framework should I select when I will use your .cshtml-file in a project via Visual Studio?

I have tried to insert your .cshtml-file in some projects there use .NET 3.0, 3.1 and 5.0. When I after that go to your website nothing happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment