React to WebListener configuration changes.
This commit is contained in:
parent
6dc0005a43
commit
7e95bf71eb
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,19 +7,6 @@ using Microsoft.Extensions.Logging;
|
|||
|
||||
namespace ServerComparison.TestSites
|
||||
{
|
||||
/// <summary>
|
||||
/// 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",
|
||||
/// },
|
||||
/// </summary>
|
||||
public class StartupHelloWorld
|
||||
{
|
||||
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 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",
|
||||
/// },
|
||||
/// </summary>
|
||||
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<WebListener>();
|
||||
if (listener != null)
|
||||
{
|
||||
listener.AuthenticationManager.AuthenticationSchemes =
|
||||
AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | AuthenticationSchemes.AllowAnonymous;
|
||||
}
|
||||
|
||||
app.Use((context, next) =>
|
||||
{
|
||||
if (context.Request.Path.Equals("/Anonymous"))
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@
|
|||
<handlers>
|
||||
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
|
||||
</handlers>
|
||||
<aspNetCore processPath=".\ServerComparison.TestSites.exe" arguments="" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
|
||||
<aspNetCore processPath=".\ServerComparison.TestSites.exe" arguments="" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="true" />
|
||||
</system.webServer>
|
||||
</configuration>
|
||||
Loading…
Reference in New Issue