From 7e95bf71ebbbdb8e25477fd88eb855b042b16721 Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 18 Apr 2016 10:07:57 -0700 Subject: [PATCH] React to WebListener configuration changes. --- test/ServerComparison.TestSites/Program.cs | 35 +++++++++++++++---- .../StartupHelloWorld.cs | 13 ------- .../StartupNtlmAuthentication.cs | 23 ------------ test/ServerComparison.TestSites/web.config | 2 +- 4 files changed, 30 insertions(+), 43 deletions(-) diff --git a/test/ServerComparison.TestSites/Program.cs b/test/ServerComparison.TestSites/Program.cs index 65b7e9f3d5..a4c6a661ee 100644 --- a/test/ServerComparison.TestSites/Program.cs +++ b/test/ServerComparison.TestSites/Program.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.Hosting; +using Microsoft.Net.Http.Server; namespace ServerComparison.TestSites { @@ -9,14 +10,36 @@ namespace ServerComparison.TestSites { public static void Main(string[] args) { - var host = new WebHostBuilder() - // We set the server by name before default args so that command line arguments can override it. - // This is used to allow deployers to choose the server for testing. - .UseServer("Microsoft.AspNetCore.Server.Kestrel") + var builder = new WebHostBuilder() .UseDefaultHostingConfiguration(args) .UseIISIntegration() - .UseStartup("ServerComparison.TestSites") - .Build(); + .UseStartup("ServerComparison.TestSites"); + + // Switch beteween Kestrel and WebListener for different tests. Default to Kestrel for normal app execution. + if (string.Equals(builder.GetSetting("server"), "Microsoft.AspNetCore.Server.WebListener", System.StringComparison.Ordinal)) + { + if (string.Equals(builder.GetSetting("environment"), "NtlmAuthentication", System.StringComparison.Ordinal)) + { + // Set up NTLM authentication for WebListener as follows. + // For IIS and IISExpress use inetmgr to setup NTLM authentication on the application or + // modify the applicationHost.config to enable NTLM. + builder.UseWebListener(options => + { + options.Listener.AuthenticationManager.AuthenticationSchemes = + AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | AuthenticationSchemes.AllowAnonymous; + }); + } + else + { + builder.UseWebListener(); + } + } + else + { + builder.UseKestrel(); + } + + var host = builder.Build(); host.Run(); } diff --git a/test/ServerComparison.TestSites/StartupHelloWorld.cs b/test/ServerComparison.TestSites/StartupHelloWorld.cs index b2d386bf3b..0c387f1b59 100644 --- a/test/ServerComparison.TestSites/StartupHelloWorld.cs +++ b/test/ServerComparison.TestSites/StartupHelloWorld.cs @@ -7,19 +7,6 @@ using Microsoft.Extensions.Logging; namespace ServerComparison.TestSites { - /// - /// To make runtime to load an environment based startup class, specify the environment by the following ways: - /// 1. Drop a Microsoft.AspNetCore.Hosting.ini file in the wwwroot folder - /// 2. Add a setting in the ini file named 'ASPNET_ENV' with value of the format 'Startup[EnvironmentName]'. For example: To load a Startup class named - /// 'StartupHelloWorld' the value of the env should be 'HelloWorld' (eg. ASPNET_ENV=HelloWorld). Runtime adds a 'Startup' prefix to this and loads 'StartupHelloWorld'. - /// If no environment name is specified the default startup class loaded is 'Startup'. - /// Alternative ways to specify environment are: - /// 1. Set the environment variable named SET ASPNET_ENV=HelloWorld - /// 2. For selfhost based servers pass in a command line variable named --env with this value. Eg: - /// "commands": { - /// "web": "Microsoft.AspNetCore.Hosting --server Microsoft.AspNetCore.Server.WebListener --server.urls http://localhost:5002 --ASPNET_ENV HelloWorld", - /// }, - /// public class StartupHelloWorld { public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) diff --git a/test/ServerComparison.TestSites/StartupNtlmAuthentication.cs b/test/ServerComparison.TestSites/StartupNtlmAuthentication.cs index df1d0070bb..639c747e35 100644 --- a/test/ServerComparison.TestSites/StartupNtlmAuthentication.cs +++ b/test/ServerComparison.TestSites/StartupNtlmAuthentication.cs @@ -5,23 +5,9 @@ using System; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; -using Microsoft.Net.Http.Server; namespace ServerComparison.TestSites { - /// - /// To make runtime to load an environment based startup class, specify the environment by the following ways: - /// 1. Drop a Microsoft.AspNetCore.Hosting.ini file in the wwwroot folder - /// 2. Add a setting in the ini file named 'ASPNET_ENV' with value of the format 'Startup[EnvironmentName]'. For example: To load a Startup class named - /// 'StartupNtlmAuthentication' the value of the env should be 'NtlmAuthentication' (eg. ASPNET_ENV=NtlmAuthentication). Runtime adds a 'Startup' prefix to this and loads 'StartupNtlmAuthentication'. - /// If no environment name is specified the default startup class loaded is 'Startup'. - /// Alternative ways to specify environment are: - /// 1. Set the environment variable named SET ASPNET_ENV=NtlmAuthentication - /// 2. For selfhost based servers pass in a command line variable named --env with this value. Eg: - /// "commands": { - /// "web": "Microsoft.AspNetCore.Hosting --server Microsoft.AspNetCore.Server.WebListener --server.urls http://localhost:5002 --ASPNET_ENV NtlmAuthentication", - /// }, - /// public class StartupNtlmAuthentication { public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) @@ -46,15 +32,6 @@ namespace ServerComparison.TestSites } }); - // Set up NTLM authentication for WebListener like below. - // For IIS and IISExpress: Use inetmgr to setup NTLM authentication on the application vDir or modify the applicationHost.config to enable NTLM. - var listener = app.ServerFeatures.Get(); - if (listener != null) - { - listener.AuthenticationManager.AuthenticationSchemes = - AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | AuthenticationSchemes.AllowAnonymous; - } - app.Use((context, next) => { if (context.Request.Path.Equals("/Anonymous")) diff --git a/test/ServerComparison.TestSites/web.config b/test/ServerComparison.TestSites/web.config index e91ebb7555..c3b3c87088 100644 --- a/test/ServerComparison.TestSites/web.config +++ b/test/ServerComparison.TestSites/web.config @@ -4,6 +4,6 @@ - + \ No newline at end of file