60 lines
2.4 KiB
C#
60 lines
2.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace IISSample
|
|
{
|
|
public class Startup
|
|
{
|
|
public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
|
|
{
|
|
loggerfactory.AddConsole(LogLevel.Debug);
|
|
|
|
var logger = loggerfactory.CreateLogger("Requests");
|
|
|
|
app.UseIISPlatformHandler();
|
|
|
|
app.Run(async (context) =>
|
|
{
|
|
logger.LogDebug("Received request: " + context.Request.Method + " " + context.Request.Path);
|
|
|
|
context.Response.ContentType = "text/plain";
|
|
await context.Response.WriteAsync("Hello World - " + DateTimeOffset.Now + Environment.NewLine);
|
|
await context.Response.WriteAsync("User - " + context.User.Identity.Name + Environment.NewLine);
|
|
await context.Response.WriteAsync("PathBase: " + context.Request.PathBase.Value + Environment.NewLine);
|
|
await context.Response.WriteAsync("Path: " + context.Request.Path.Value + Environment.NewLine);
|
|
await context.Response.WriteAsync("ClientCert: " + context.Connection.ClientCertificate + Environment.NewLine);
|
|
|
|
await context.Response.WriteAsync(Environment.NewLine + "Headers:" + Environment.NewLine);
|
|
foreach (var header in context.Request.Headers)
|
|
{
|
|
await context.Response.WriteAsync(header.Key + ": " + header.Value + Environment.NewLine);
|
|
}
|
|
|
|
await context.Response.WriteAsync(Environment.NewLine + "Environment Variables:" + Environment.NewLine);
|
|
var vars = Environment.GetEnvironmentVariables();
|
|
foreach (var key in vars.Keys)
|
|
{
|
|
var value = vars[key];
|
|
await context.Response.WriteAsync(key + ": " + value + Environment.NewLine);
|
|
}
|
|
});
|
|
}
|
|
|
|
public static void Main(string[] args)
|
|
{
|
|
var host = new WebHostBuilder()
|
|
.UseDefaultConfiguration(args)
|
|
.UseServer("Microsoft.AspNetCore.Server.Kestrel")
|
|
.UseIISPlatformHandlerUrl()
|
|
.UseStartup<Startup>()
|
|
.Build();
|
|
|
|
host.Run();
|
|
}
|
|
}
|
|
}
|