public static void UseEnvCheck(this IApplicationBuilder app, string path = "/env") { app.Map(path, s => { s.Run(async context => { var env = AppEnvironment.GetAppEnvironment(); context.Response.ContentType = DEFAULT_CONTENT_TYPE; await context.Response.WriteAsync(Serialize(env)); }); }); }
public static AppEnvironment GetAppEnvironment() { var env = new AppEnvironment { ProcessId = Process.GetCurrentProcess().Id, ProcessStartTime = Process.GetCurrentProcess().StartTime.ToUniversalTime(), Hostname = Dns.GetHostName() }; var envVars = Environment.GetEnvironmentVariables(); foreach (var envVarKey in envVars.Keys) { env.EnvironmentVariables.Add(envVarKey.ToString(), envVars[envVarKey].ToString()); } return(env); }
public static void UseEnvCheck(this IApplicationBuilder app, string path = "/env") { app.Map(path, s => { s.Run(async context => { var remoteIp = context.Connection.RemoteIpAddress; if (!IPAddress.IsLoopback(remoteIp)) { context.Response.StatusCode = 403; context.Response.ContentType = "application/html"; await context.Response.WriteAsync("<font size=\"7\">403</font><br/>"); } else { var env = AppEnvironment.GetAppEnvironment(); context.Response.ContentType = DEFAULT_CONTENT_TYPE; await context.Response.WriteAsync(Serialize(env)); } }); }); }