// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Linq; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.IISIntegration; namespace NativeIISSample { public class Startup { // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IAuthenticationSchemeProvider authSchemeProvider) { app.Run(async (context) => { context.Response.ContentType = "text/plain"; await context.Response.WriteAsync("Hello World - " + DateTimeOffset.Now + Environment.NewLine); await context.Response.WriteAsync(Environment.NewLine); await context.Response.WriteAsync("Address:" + Environment.NewLine); await context.Response.WriteAsync("Scheme: " + context.Request.Scheme + Environment.NewLine); await context.Response.WriteAsync("Host: " + context.Request.Headers["Host"] + 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("Query: " + context.Request.QueryString.Value + Environment.NewLine); await context.Response.WriteAsync(Environment.NewLine); await context.Response.WriteAsync("Connection:" + Environment.NewLine); await context.Response.WriteAsync("RemoteIp: " + context.Connection.RemoteIpAddress + Environment.NewLine); await context.Response.WriteAsync("RemotePort: " + context.Connection.RemotePort + Environment.NewLine); await context.Response.WriteAsync("LocalIp: " + context.Connection.LocalIpAddress + Environment.NewLine); await context.Response.WriteAsync("LocalPort: " + context.Connection.LocalPort + Environment.NewLine); await context.Response.WriteAsync("ClientCert: " + context.Connection.ClientCertificate + Environment.NewLine); await context.Response.WriteAsync(Environment.NewLine); await context.Response.WriteAsync("User: " + context.User.Identity.Name + Environment.NewLine); var scheme = await authSchemeProvider.GetSchemeAsync(IISDefaults.AuthenticationScheme); await context.Response.WriteAsync("DisplayName: " + scheme?.DisplayName + Environment.NewLine); await context.Response.WriteAsync(Environment.NewLine); await context.Response.WriteAsync("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); await context.Response.WriteAsync("Environment Variables:" + Environment.NewLine); var vars = Environment.GetEnvironmentVariables(); foreach (var key in vars.Keys.Cast().OrderBy(key => key, StringComparer.OrdinalIgnoreCase)) { var value = vars[key]; await context.Response.WriteAsync(key + ": " + value + Environment.NewLine); } await context.Response.WriteAsync(Environment.NewLine); // accessing IIS server variables await context.Response.WriteAsync("Server Variables:" + Environment.NewLine); if (context.Features.Get() != null) { await context.Response.WriteAsync("Websocket feature is enabled."); } else { await context.Response.WriteAsync("Websocket feature is disabled."); } }); } public static void Main(string[] args) { var host = new WebHostBuilder() .UseIISIntegration() .UseStartup() .Build(); host.Run(); } } }