[IIS] Move to GenericHost (#24280)

This commit is contained in:
Kahbazi 2020-07-28 22:32:09 +04:30 committed by GitHub
parent 0437117cfb
commit 085921305a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 360 additions and 231 deletions

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
@ -12,6 +13,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.IIS; using Microsoft.AspNetCore.Server.IIS;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace NativeIISSample namespace NativeIISSample
{ {
@ -115,16 +117,20 @@ namespace NativeIISSample
"WEBSOCKET_VERSION" "WEBSOCKET_VERSION"
}; };
public static void Main(string[] args) public static Task Main(string[] args)
{ {
var host = new WebHostBuilder() var host = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseKestrel() .UseKestrel()
.UseIIS() .UseIIS()
.UseIISIntegration() .UseIISIntegration()
.UseStartup<Startup>() .UseStartup<Startup>();
})
.Build(); .Build();
host.Run(); return host.RunAsync();
} }
} }
} }

View File

@ -23,7 +23,7 @@ using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
{ {
public class TestServer: IDisposable, IStartup public class TestServer : IDisposable
{ {
private const string InProcessHandlerDll = "aspnetcorev2_inprocess.dll"; private const string InProcessHandlerDll = "aspnetcorev2_inprocess.dll";
private const string AspNetCoreModuleDll = "aspnetcorev2.dll"; private const string AspNetCoreModuleDll = "aspnetcorev2.dll";
@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
public TestConnection CreateConnection() => new TestConnection(_currentPort); public TestConnection CreateConnection() => new TestConnection(_currentPort);
private static IISServerOptions _options; private static IISServerOptions _options;
private IWebHost _host; private IHost _host;
private string _appHostConfigPath; private string _appHostConfigPath;
private int _currentPort; private int _currentPort;
@ -131,16 +131,24 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
private int Main(IntPtr argc, IntPtr argv) private int Main(IntPtr argc, IntPtr argv)
{ {
var builder = new WebHostBuilder() _host = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseIIS() .UseIIS()
.UseSetting(WebHostDefaults.ApplicationKey, typeof(TestServer).GetTypeInfo().Assembly.FullName)
.Configure(app =>
{
app.Map("/start", builder => builder.Run(context => context.Response.WriteAsync("Done")));
_appBuilder(app);
})
.ConfigureServices(services => .ConfigureServices(services =>
{ {
services.Configure<IISServerOptions>(options => options.MaxRequestBodySize = _options.MaxRequestBodySize); services.Configure<IISServerOptions>(options => options.MaxRequestBodySize = _options.MaxRequestBodySize);
services.AddSingleton<IStartup>(this);
services.AddSingleton(_loggerFactory); services.AddSingleton(_loggerFactory);
});
}) })
.UseSetting(WebHostDefaults.ApplicationKey, typeof(TestServer).GetTypeInfo().Assembly.FullName); .Build();
_host = builder.Build();
var doneEvent = new ManualResetEventSlim(); var doneEvent = new ManualResetEventSlim();
var lifetime = _host.Services.GetService<IHostApplicationLifetime>(); var lifetime = _host.Services.GetService<IHostApplicationLifetime>();
@ -167,17 +175,6 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
WebCoreLock.Release(); WebCoreLock.Release();
} }
public IServiceProvider ConfigureServices(IServiceCollection services)
{
return services.BuildServiceProvider();
}
public void Configure(IApplicationBuilder app)
{
app.Map("/start", builder => builder.Run(context => context.Response.WriteAsync("Done")));
_appBuilder(app);
}
private delegate int hostfxr_main_fn(IntPtr argc, IntPtr argv); private delegate int hostfxr_main_fn(IntPtr argc, IntPtr argv);
[DllImport(HWebCoreDll)] [DllImport(HWebCoreDll)]
@ -195,7 +192,7 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
[DllImport(InProcessHandlerDll)] [DllImport(InProcessHandlerDll)]
private static extern int set_main_handler(hostfxr_main_fn main); private static extern int set_main_handler(hostfxr_main_fn main);
[DllImport("kernel32", SetLastError=true, CharSet = CharSet.Ansi)] [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
private static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpFileName); private static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string lpFileName);
private void Retry(Action func, int attempts) private void Retry(Action func, int attempts)

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
@ -10,6 +11,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.IISIntegration; using Microsoft.AspNetCore.Server.IISIntegration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace IISSample namespace IISSample
@ -88,19 +90,23 @@ namespace IISSample
}); });
} }
public static void Main(string[] args) public static Task Main(string[] args)
{ {
var host = new WebHostBuilder() var host = new HostBuilder()
.ConfigureWebHost(webHostBuidler =>
{
webHostBuidler
.UseKestrel()
.UseStartup<Startup>();
})
.ConfigureLogging((_, factory) => .ConfigureLogging((_, factory) =>
{ {
factory.AddConsole(); factory.AddConsole();
factory.AddFilter("Console", level => level >= LogLevel.Debug); factory.AddFilter("Console", level => level >= LogLevel.Debug);
}) })
.UseKestrel()
.UseStartup<Startup>()
.Build(); .Build();
host.Run(); return host.RunAsync();
} }
} }
} }

View File

@ -2,9 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost; using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Server.IISIntegration namespace Microsoft.AspNetCore.Server.IISIntegration
@ -12,19 +14,27 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
public class IISExtensionTests public class IISExtensionTests
{ {
[Fact] [Fact]
public void CallingUseIISIntegrationMultipleTimesWorks() public async Task CallingUseIISIntegrationMultipleTimesWorks()
{ {
using var host = new HostBuilder()
var builder = new WebHostBuilder() .ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseSetting("TOKEN", "TestToken") .UseSetting("TOKEN", "TestToken")
.UseSetting("PORT", "12345") .UseSetting("PORT", "12345")
.UseSetting("APPL_PATH", "/") .UseSetting("APPL_PATH", "/")
.UseIISIntegration() .UseIISIntegration()
.UseIISIntegration() .UseIISIntegration()
.Configure(app => { }); .Configure(app => { })
var server = new TestServer(builder); .UseTestServer();
})
.Build();
var filters = server.Host.Services.GetServices<IStartupFilter>() var server = host.GetTestServer();
await host.StartAsync();
var filters = server.Services.GetServices<IStartupFilter>()
.OfType<IISSetupFilter>(); .OfType<IISSetupFilter>();
Assert.Single(filters); Assert.Single(filters);

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
@ -12,6 +11,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http.Features.Authentication; using Microsoft.AspNetCore.Http.Features.Authentication;
using Microsoft.AspNetCore.TestHost; using Microsoft.AspNetCore.TestHost;
using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Xunit; using Xunit;
@ -25,7 +25,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
{ {
var assertsExecuted = false; var assertsExecuted = false;
var builder = new WebHostBuilder() using var host = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseSetting("PORT", "12345") .UseSetting("PORT", "12345")
.UseSetting("APPL_PATH", "/") .UseSetting("APPL_PATH", "/")
.UseIISIntegration() .UseIISIntegration()
@ -38,8 +41,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
assertsExecuted = true; assertsExecuted = true;
return Task.FromResult(0); return Task.FromResult(0);
}); });
}); })
var server = new TestServer(builder); .UseTestServer();
})
.Build();
var server = host.GetTestServer();
await host.StartAsync();
var req = new HttpRequestMessage(HttpMethod.Get, ""); var req = new HttpRequestMessage(HttpMethod.Get, "");
req.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken"); req.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
@ -53,7 +62,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
{ {
var assertsExecuted = false; var assertsExecuted = false;
var builder = new WebHostBuilder() using var host = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseSetting("TOKEN", "TestToken") .UseSetting("TOKEN", "TestToken")
.UseSetting("PORT", "12345") .UseSetting("PORT", "12345")
.UseSetting("APPL_PATH", "/") .UseSetting("APPL_PATH", "/")
@ -67,8 +79,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
assertsExecuted = true; assertsExecuted = true;
return Task.FromResult(0); return Task.FromResult(0);
}); });
}); })
var server = new TestServer(builder); .UseTestServer();
})
.Build();
var server = host.GetTestServer();
await host.StartAsync();
var req = new HttpRequestMessage(HttpMethod.Get, ""); var req = new HttpRequestMessage(HttpMethod.Get, "");
var response = await server.CreateClient().SendAsync(req); var response = await server.CreateClient().SendAsync(req);
@ -85,7 +103,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
{ {
var requestExecuted = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously); var requestExecuted = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
var applicationStoppingFired = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously); var applicationStoppingFired = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
var builder = new WebHostBuilder() using var host = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseSetting("TOKEN", "TestToken") .UseSetting("TOKEN", "TestToken")
.UseSetting("PORT", "12345") .UseSetting("PORT", "12345")
.UseSetting("APPL_PATH", pathBase) .UseSetting("APPL_PATH", pathBase)
@ -100,8 +121,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
requestExecuted.SetResult(0); requestExecuted.SetResult(0);
return Task.FromResult(0); return Task.FromResult(0);
}); });
}); })
var server = new TestServer(builder); .UseTestServer();
})
.Build();
var server = host.GetTestServer();
await host.StartAsync();
var request = new HttpRequestMessage(HttpMethod.Post, requestPath); var request = new HttpRequestMessage(HttpMethod.Post, requestPath);
request.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken"); request.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
@ -135,7 +162,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
{ {
var requestExecuted = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously); var requestExecuted = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
var applicationStoppingFired = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously); var applicationStoppingFired = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
var builder = new WebHostBuilder() using var host = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseSetting("TOKEN", "TestToken") .UseSetting("TOKEN", "TestToken")
.UseSetting("PORT", "12345") .UseSetting("PORT", "12345")
.UseSetting("APPL_PATH", "/") .UseSetting("APPL_PATH", "/")
@ -150,8 +180,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
requestExecuted.SetResult(0); requestExecuted.SetResult(0);
return Task.FromResult(0); return Task.FromResult(0);
}); });
}); })
var server = new TestServer(builder); .UseTestServer();
})
.Build();
var server = host.GetTestServer();
await host.StartAsync();
var request = new HttpRequestMessage(method, "/iisintegration"); var request = new HttpRequestMessage(method, "/iisintegration");
request.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken"); request.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
@ -171,7 +207,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
{ {
var requestExecuted = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously); var requestExecuted = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
var applicationStoppingFired = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously); var applicationStoppingFired = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
var builder = new WebHostBuilder() using var host = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseSetting("TOKEN", "TestToken") .UseSetting("TOKEN", "TestToken")
.UseSetting("PORT", "12345") .UseSetting("PORT", "12345")
.UseSetting("APPL_PATH", "/") .UseSetting("APPL_PATH", "/")
@ -186,8 +225,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
requestExecuted.SetResult(0); requestExecuted.SetResult(0);
return Task.FromResult(0); return Task.FromResult(0);
}); });
}); })
var server = new TestServer(builder); .UseTestServer();
})
.Build();
var server = host.GetTestServer();
await host.StartAsync();
var request = new HttpRequestMessage(HttpMethod.Post, path); var request = new HttpRequestMessage(HttpMethod.Post, path);
request.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken"); request.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
@ -207,7 +252,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
{ {
var requestExecuted = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously); var requestExecuted = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
var applicationStoppingFired = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously); var applicationStoppingFired = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
var builder = new WebHostBuilder() using var host = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseSetting("TOKEN", "TestToken") .UseSetting("TOKEN", "TestToken")
.UseSetting("PORT", "12345") .UseSetting("PORT", "12345")
.UseSetting("APPL_PATH", "/") .UseSetting("APPL_PATH", "/")
@ -222,8 +270,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
requestExecuted.SetResult(0); requestExecuted.SetResult(0);
return Task.FromResult(0); return Task.FromResult(0);
}); });
}); })
var server = new TestServer(builder); .UseTestServer();
})
.Build();
var server = host.GetTestServer();
await host.StartAsync();
var request = new HttpRequestMessage(HttpMethod.Post, "/iisintegration"); var request = new HttpRequestMessage(HttpMethod.Post, "/iisintegration");
request.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken"); request.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
@ -236,9 +290,12 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
} }
[Fact] [Fact]
public void UrlDelayRegisteredAndPreferHostingUrlsSet() public async Task UrlDelayRegisteredAndPreferHostingUrlsSet()
{ {
var builder = new WebHostBuilder() using var host = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseSetting("TOKEN", "TestToken") .UseSetting("TOKEN", "TestToken")
.UseSetting("PORT", "12345") .UseSetting("PORT", "12345")
.UseSetting("APPL_PATH", "/") .UseSetting("APPL_PATH", "/")
@ -248,20 +305,30 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
app.Run(context => Task.FromResult(0)); app.Run(context => Task.FromResult(0));
}); });
Assert.Null(builder.GetSetting(WebHostDefaults.ServerUrlsKey)); Assert.Null(webHostBuilder.GetSetting(WebHostDefaults.ServerUrlsKey));
Assert.Null(builder.GetSetting(WebHostDefaults.PreferHostingUrlsKey)); Assert.Null(webHostBuilder.GetSetting(WebHostDefaults.PreferHostingUrlsKey));
// Adds a server and calls Build() webHostBuilder.UseTestServer();
var server = new TestServer(builder); })
.Build();
Assert.Equal("http://127.0.0.1:12345", builder.GetSetting(WebHostDefaults.ServerUrlsKey)); var server = host.GetTestServer();
Assert.Equal("true", builder.GetSetting(WebHostDefaults.PreferHostingUrlsKey));
await host.StartAsync();
var configuration = host.Services.GetService<IConfiguration>();
Assert.Equal("http://127.0.0.1:12345", configuration[WebHostDefaults.ServerUrlsKey]);
Assert.Equal("true", configuration[WebHostDefaults.PreferHostingUrlsKey]);
} }
[Fact] [Fact]
public void PathBaseHiddenFromServer() public async Task PathBaseHiddenFromServer()
{ {
var builder = new WebHostBuilder() using var host = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseSetting("TOKEN", "TestToken") .UseSetting("TOKEN", "TestToken")
.UseSetting("PORT", "12345") .UseSetting("PORT", "12345")
.UseSetting("APPL_PATH", "/pathBase") .UseSetting("APPL_PATH", "/pathBase")
@ -269,10 +336,17 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
.Configure(app => .Configure(app =>
{ {
app.Run(context => Task.FromResult(0)); app.Run(context => Task.FromResult(0));
}); })
new TestServer(builder); .UseTestServer();
})
.Build();
Assert.Equal("http://127.0.0.1:12345", builder.GetSetting(WebHostDefaults.ServerUrlsKey)); host.GetTestServer();
await host.StartAsync();
var configuration = host.Services.GetService<IConfiguration>();
Assert.Equal("http://127.0.0.1:12345", configuration[WebHostDefaults.ServerUrlsKey]);
} }
[Fact] [Fact]
@ -280,7 +354,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
{ {
var requestPathBase = string.Empty; var requestPathBase = string.Empty;
var requestPath = string.Empty; var requestPath = string.Empty;
var builder = new WebHostBuilder() using var host = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseSetting("TOKEN", "TestToken") .UseSetting("TOKEN", "TestToken")
.UseSetting("PORT", "12345") .UseSetting("PORT", "12345")
.UseSetting("APPL_PATH", "/pathbase") .UseSetting("APPL_PATH", "/pathbase")
@ -293,8 +370,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
requestPath = context.Request.Path.Value; requestPath = context.Request.Path.Value;
return Task.FromResult(0); return Task.FromResult(0);
}); });
}); })
var server = new TestServer(builder); .UseTestServer();
})
.Build();
var server = host.GetTestServer();
await host.StartAsync();
var request = new HttpRequestMessage(HttpMethod.Get, "/PathBase/Path"); var request = new HttpRequestMessage(HttpMethod.Get, "/PathBase/Path");
request.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken"); request.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
@ -309,7 +392,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
{ {
var assertsExecuted = false; var assertsExecuted = false;
var builder = new WebHostBuilder() using var host = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseSetting("TOKEN", "TestToken") .UseSetting("TOKEN", "TestToken")
.UseSetting("PORT", "12345") .UseSetting("PORT", "12345")
.UseSetting("APPL_PATH", "/") .UseSetting("APPL_PATH", "/")
@ -325,8 +411,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
Assert.Equal("Microsoft.AspNetCore.Server.IISIntegration.AuthenticationHandler", windows.HandlerType.FullName); Assert.Equal("Microsoft.AspNetCore.Server.IISIntegration.AuthenticationHandler", windows.HandlerType.FullName);
assertsExecuted = true; assertsExecuted = true;
}); });
}); })
var server = new TestServer(builder); .UseTestServer();
})
.Build();
var server = host.GetTestServer();
await host.StartAsync();
var req = new HttpRequestMessage(HttpMethod.Get, ""); var req = new HttpRequestMessage(HttpMethod.Get, "");
req.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken"); req.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
@ -342,18 +434,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
{ {
var assertsExecuted = false; var assertsExecuted = false;
var builder = new WebHostBuilder() using var host = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseSetting("TOKEN", "TestToken") .UseSetting("TOKEN", "TestToken")
.UseSetting("PORT", "12345") .UseSetting("PORT", "12345")
.UseSetting("APPL_PATH", "/") .UseSetting("APPL_PATH", "/")
.UseIISIntegration() .UseIISIntegration()
.ConfigureServices(services =>
{
services.Configure<IISOptions>(options =>
{
options.ForwardWindowsAuthentication = forward;
});
})
.Configure(app => .Configure(app =>
{ {
app.Run(async context => app.Run(async context =>
@ -373,8 +461,21 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
} }
assertsExecuted = true; assertsExecuted = true;
}); });
})
.UseTestServer();
})
.ConfigureServices(services =>
{
services.Configure<IISOptions>(options =>
{
options.ForwardWindowsAuthentication = forward;
}); });
var server = new TestServer(builder); })
.Build();
var server = host.GetTestServer();
await host.StartAsync();
var req = new HttpRequestMessage(HttpMethod.Get, ""); var req = new HttpRequestMessage(HttpMethod.Get, "");
req.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken"); req.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");
@ -390,18 +491,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
{ {
var assertsExecuted = false; var assertsExecuted = false;
var builder = new WebHostBuilder() using var host = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseSetting("TOKEN", "TestToken") .UseSetting("TOKEN", "TestToken")
.UseSetting("PORT", "12345") .UseSetting("PORT", "12345")
.UseSetting("APPL_PATH", "/") .UseSetting("APPL_PATH", "/")
.UseIISIntegration() .UseIISIntegration()
.ConfigureServices(services =>
{
services.Configure<IISOptions>(options =>
{
options.ForwardWindowsAuthentication = forward;
});
})
.Configure(app => .Configure(app =>
{ {
app.Run(context => app.Run(context =>
@ -409,8 +506,21 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
assertsExecuted = true; assertsExecuted = true;
return Task.FromResult(0); return Task.FromResult(0);
}); });
})
.UseTestServer();
})
.ConfigureServices(services =>
{
services.Configure<IISOptions>(options =>
{
options.ForwardWindowsAuthentication = forward;
}); });
var server = new TestServer(builder); })
.Build();
var server = host.GetTestServer();
await host.StartAsync();
var req = new HttpRequestMessage(HttpMethod.Get, ""); var req = new HttpRequestMessage(HttpMethod.Get, "");
req.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken"); req.Headers.TryAddWithoutValidation("MS-ASPNETCORE-TOKEN", "TestToken");