Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5102b25
Initial plan
Copilot Jul 17, 2025
54f0cdd
Mark WebHostBuilder class as obsolete with placeholder message
Copilot Jul 17, 2025
8c3f586
Update WebHostBuilder usage to HostBuilder pattern in four target files
Copilot Jul 17, 2025
8869208
fixup
BrennanConroy Jul 17, 2025
5407fb0
Address review feedback: Add pragma disables and update to HostBuilde…
Copilot Jul 17, 2025
dd80d9c
Add pragma warning suppression for WebHost.cs and remove from WebHost…
Copilot Jul 17, 2025
3f16853
Update TestServerTests.cs and HttpsConfigurationTests.cs to use HostB…
Copilot Jul 17, 2025
d028735
test
BrennanConroy Jul 17, 2025
95e6eaa
fix tests
BrennanConroy Jul 18, 2025
194d366
Remove nowarn settings and start converting TestHost tests to HostBui…
Copilot Jul 18, 2025
e87e383
Complete conversion of RequestBuilderTests, ClientHandlerTests, and W…
Copilot Jul 18, 2025
bd4d52f
Start converting TestHost test files to HostBuilder pattern
Copilot Jul 19, 2025
b146f4d
Complete conversion of HttpContextBuilderTests.cs to HostBuilder pattern
Copilot Jul 19, 2025
2f609b9
Partial conversion of TestClientTests.cs and TestServerTests.cs to Ho…
Copilot Jul 19, 2025
dfcad52
Complete TestHost test file WebHostBuilder conversion - added pragma …
Copilot Jul 20, 2025
9134e94
startasync
BrennanConroy Jul 21, 2025
f6c7ee3
convert
BrennanConroy Jul 21, 2025
161a1b5
Convert 12 more TestServerTests to HostBuilder pattern
Copilot Jul 22, 2025
5279775
testservertests
BrennanConroy Jul 23, 2025
ac08998
Update WebHostBuilder obsolete attribute to use ASPDEPR004 diagnostic ID
Copilot Jul 24, 2025
d63a4a8
Apply suggestions from code review
BrennanConroy Jul 24, 2025
c151d24
Update src/Hosting/TestHost/test/TestClientTests.cs
BrennanConroy Jul 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ public async Task WebhostLoadsKeyRingBeforeServerStarts()
.Returns(Mock.Of<IKeyRing>())
.Callback(() => tcs.TrySetResult());

var builder = new WebHostBuilder()
.UseStartup<TestStartup>()
var builder = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseStartup<TestStartup>();
})
.ConfigureServices(s =>
s.AddDataProtection()
.Services
Expand Down
1 change: 1 addition & 0 deletions src/Hosting/Hosting/src/WebHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Microsoft.AspNetCore.Hosting;
/// <summary>
/// A builder for <see cref="IWebHost"/>
/// </summary>
[Obsolete("TODO: Add Obsolete message")]
public class WebHostBuilder : IWebHostBuilder
{
private readonly HostingEnvironment _hostingEnvironment;
Expand Down
9 changes: 9 additions & 0 deletions src/Hosting/Hosting/test/WebHostBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ public void DoNotCaptureStartupErrorsByDefault(IWebHostBuilder builder)
public void ServiceProviderDisposedOnBuildException()
{
var service = new DisposableService();
#pragma warning disable CS0618 // Type or member is obsolete
var hostBuilder = new WebHostBuilder()
.UseServer(new TestServer())
.ConfigureServices(services =>
Expand All @@ -437,6 +438,7 @@ public void ServiceProviderDisposedOnBuildException()
services.AddSingleton(sp => service);
})
.UseStartup<StartupWithResolvedDisposableThatThrows>();
#pragma warning restore CS0618 // Type or member is obsolete

Assert.Throws<InvalidOperationException>(() => hostBuilder.Build());
Assert.True(service.Disposed);
Expand Down Expand Up @@ -1483,14 +1485,18 @@ private IWebHostBuilder CreateWebHostBuilder()
.AddInMemoryCollection(vals);
var config = builder.Build();

#pragma warning disable CS0618 // Type or member is obsolete
return new WebHostBuilder().UseConfiguration(config);
#pragma warning restore CS0618 // Type or member is obsolete
}

#pragma warning disable CS0618 // Type or member is obsolete
public static TheoryData<IWebHostBuilder> DefaultWebHostBuilders => new TheoryData<IWebHostBuilder>
{
new WebHostBuilder(),
new GenericWebHostBuilderWrapper(new HostBuilder())
};
#pragma warning restore CS0618 // Type or member is obsolete

public static TheoryData<IWebHostBuilder> DefaultWebHostBuildersWithConfig
{
Expand All @@ -1506,10 +1512,12 @@ public static TheoryData<IWebHostBuilder> DefaultWebHostBuildersWithConfig
.AddInMemoryCollection(vals);
var config = builder.Build();

#pragma warning disable CS0618 // Type or member is obsolete
return new TheoryData<IWebHostBuilder> {
new WebHostBuilder().UseConfiguration(config),
new GenericWebHostBuilderWrapper(new HostBuilder()).UseConfiguration(config)
};
#pragma warning restore CS0618 // Type or member is obsolete
}
}

Expand Down Expand Up @@ -1783,3 +1791,4 @@ public void Dispose()
public void AddProvider(ILoggerProvider provider) { }
}
}
//#pragma warning restore CS0618 // Type or member is obsolete
2 changes: 2 additions & 0 deletions src/Hosting/Hosting/test/WebHostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,9 @@ private IWebHost CreateHost(RequestDelegate requestDelegate)

private IWebHostBuilder CreateBuilder(IConfiguration config = null)
{
#pragma warning disable CS0618 // Type or member is obsolete
return new WebHostBuilder().UseConfiguration(config ?? new ConfigurationBuilder().Build()).UseStartup("Microsoft.AspNetCore.Hosting.Tests");
#pragma warning restore CS0618 // Type or member is obsolete
}

private static bool[] RegisterCallbacksThatThrow(IServiceCollection services)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<!-- CS0618: WebHostBuilder is obsolete -->
<NoWarn>$(NoWarn);CS0618</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<!-- CS0618: WebHostBuilder is obsolete -->
<NoWarn>$(NoWarn);CS0618</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
<!-- CS0618: WebHostBuilder is obsolete -->
<NoWarn>$(NoWarn);CS0618</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
<!-- CS0618: WebHostBuilder is obsolete -->
<NoWarn>$(NoWarn);CS0618</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
86 changes: 55 additions & 31 deletions src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@
return 12;
case "HangOnStop":
{
var host = new WebHostBuilder()
.UseIIS()
.UseStartup<Startup>()
var host = new HostBuilder()

Check failure on line 59 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: Ubuntu x64)

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L59

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(59,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: Ubuntu x64)

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L59

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(59,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: macOS)

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L59

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(59,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: macOS)

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L59

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(59,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 59 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L59

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(59,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseIIS()
.UseStartup<Startup>();
})
.Build();
host.Run();

Expand All @@ -67,10 +71,14 @@
break;
case "IncreaseShutdownLimit":
{
var host = new WebHostBuilder()
.UseIIS()
.UseShutdownTimeout(TimeSpan.FromSeconds(120))
.UseStartup<Startup>()
var host = new HostBuilder()

Check failure on line 74 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: Ubuntu x64)

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L74

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(74,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 74 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: Ubuntu x64)

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L74

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(74,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 74 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: macOS)

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L74

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(74,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 74 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: macOS)

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L74

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(74,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 74 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L74

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(74,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseIIS()
.UseShutdownTimeout(TimeSpan.FromSeconds(120))
.UseStartup<Startup>();
})
.Build();

host.Run();
Expand All @@ -94,11 +102,15 @@
return 0;
case "OverriddenServer":
{
var host = new WebHostBuilder()
.UseIIS()
.ConfigureServices(services => services.AddSingleton<IServer, DummyServer>())
.Configure(builder => builder.Run(async context => { await context.Response.WriteAsync("I shouldn't work"); }))
.Build();
var host = new HostBuilder()

Check failure on line 105 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: Ubuntu x64)

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L105

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(105,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 105 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: Ubuntu x64)

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L105

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(105,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 105 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: macOS)

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L105

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(105,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 105 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: macOS)

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L105

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(105,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 105 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L105

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(105,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseIIS()
.ConfigureServices(services => services.AddSingleton<IServer, DummyServer>())
.Configure(builder => builder.Run(async context => { await context.Response.WriteAsync("I shouldn't work"); }));
})
.Build();
host.Run();
}
break;
Expand All @@ -111,18 +123,22 @@
#if !FORWARDCOMPAT
case "DecreaseRequestLimit":
{
var host = new WebHostBuilder()
var host = new HostBuilder()
.ConfigureLogging((_, factory) =>
{
factory.AddConsole();
factory.AddFilter("Console", level => level >= LogLevel.Information);
})
.UseIIS()
.ConfigureServices(services =>
.ConfigureWebHost(webHostBuilder =>
{
services.Configure<IISServerOptions>(options => options.MaxRequestBodySize = 2);
webHostBuilder
.UseIIS()
.ConfigureServices(services =>
{
services.Configure<IISServerOptions>(options => options.MaxRequestBodySize = 2);
})
.UseStartup<Startup>();
})
.UseStartup<Startup>()
.Build();

host.Run();
Expand All @@ -131,15 +147,19 @@
#endif
case "ThrowInStartup":
{
var host = new WebHostBuilder()
.ConfigureLogging((_, factory) =>
{
factory.AddConsole();
factory.AddFilter("Console", level => level >= LogLevel.Information);
})
.UseIIS()
.UseStartup<ThrowingStartup>()
.Build();
var host = new HostBuilder()

Check failure on line 150 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: Ubuntu x64)

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L150

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(150,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 150 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: Ubuntu x64)

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L150

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(150,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 150 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: macOS)

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L150

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(150,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 150 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: macOS)

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L150

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(150,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 150 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L150

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(150,36): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)
.ConfigureLogging((_, factory) =>
{
factory.AddConsole();
factory.AddFilter("Console", level => level >= LogLevel.Information);
})
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseIIS()
.UseStartup<ThrowingStartup>();
})
.Build();

host.Run();
}
Expand Down Expand Up @@ -189,16 +209,20 @@

private static int StartServer()
{
var host = new WebHostBuilder()
var host = new HostBuilder()

Check failure on line 212 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: Ubuntu x64)

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L212

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(212,24): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 212 in src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: macOS)

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs#L212

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs(212,24): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'HostBuilder' could not be found (are you missing a using directive or an assembly reference?)
.ConfigureLogging((_, factory) =>
{
factory.AddConsole();
factory.AddFilter("Console", level => level >= LogLevel.Information);
})
.UseKestrel()
.UseIIS()
.UseIISIntegration()
.UseStartup<Startup>()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseKestrel()
.UseIIS()
.UseIISIntegration()
.UseStartup<Startup>();
})
.Build();

host.Run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,39 +345,43 @@ public async Task TlsHandshakeCallbackOptions_Invoked()
[InlineData(false, false, false)]
public async Task UseKestrelCore_CodeBased(bool useQuic, bool useHttps, bool useHttpsEnablesHttpsConfiguration)
{
var hostBuilder = new WebHostBuilder()
.UseKestrelCore()
.ConfigureKestrel(serverOptions =>
{
serverOptions.ListenAnyIP(0, listenOptions =>
var hostBuilder = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseKestrelCore()
.ConfigureKestrel(serverOptions =>
{
listenOptions.Protocols = HttpProtocols.Http3;
if (useHttps)
serverOptions.ListenAnyIP(0, listenOptions =>
{
if (useHttpsEnablesHttpsConfiguration)
listenOptions.Protocols = HttpProtocols.Http3;
if (useHttps)
{
listenOptions.UseHttps(httpsOptions =>
if (useHttpsEnablesHttpsConfiguration)
{
httpsOptions.ServerCertificate = TestResources.GetTestCertificate();
});
}
else
{
// Specifically choose an overload that doesn't enable https configuration
listenOptions.UseHttps(new HttpsConnectionAdapterOptions
listenOptions.UseHttps(httpsOptions =>
{
httpsOptions.ServerCertificate = TestResources.GetTestCertificate();
});
}
else
{
ServerCertificate = TestResources.GetTestCertificate()
});
// Specifically choose an overload that doesn't enable https configuration
listenOptions.UseHttps(new HttpsConnectionAdapterOptions
{
ServerCertificate = TestResources.GetTestCertificate()
});
}
}
}
});
})
.Configure(app => { });
});
})
.Configure(app => { });

if (useQuic)
{
hostBuilder.UseQuic();
}
if (useQuic)
{
webHostBuilder.UseQuic();
}
});

var host = hostBuilder.Build();

Expand All @@ -400,25 +404,29 @@ public async Task UseKestrelCore_CodeBased(bool useQuic, bool useHttps, bool use
[InlineData(false)]
public void UseKestrelCore_ConfigurationBased(bool useQuic)
{
var hostBuilder = new WebHostBuilder()
.UseKestrelCore()
.ConfigureKestrel(serverOptions =>
{
var config = new ConfigurationBuilder().AddInMemoryCollection(new[]
var hostBuilder = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseKestrelCore()
.ConfigureKestrel(serverOptions =>
{
new KeyValuePair<string, string>("Endpoints:end1:Url", "https://127.0.0.1:0"),
new KeyValuePair<string, string>("Endpoints:end1:Protocols", "Http3"),
new KeyValuePair<string, string>("Certificates:Default:Path", Path.Combine("shared", "TestCertificates", "aspnetdevcert.pfx")),
new KeyValuePair<string, string>("Certificates:Default:Password", "testPassword"),
}).Build();
serverOptions.Configure(config);
})
.Configure(app => { });

if (useQuic)
{
hostBuilder.UseQuic();
}
var config = new ConfigurationBuilder().AddInMemoryCollection(new[]
{
new KeyValuePair<string, string>("Endpoints:end1:Url", "https://127.0.0.1:0"),
new KeyValuePair<string, string>("Endpoints:end1:Protocols", "Http3"),
new KeyValuePair<string, string>("Certificates:Default:Path", Path.Combine("shared", "TestCertificates", "aspnetdevcert.pfx")),
new KeyValuePair<string, string>("Certificates:Default:Password", "testPassword"),
}).Build();
serverOptions.Configure(config);
})
.Configure(app => { });

if (useQuic)
{
webHostBuilder.UseQuic();
}
});

var host = hostBuilder.Build();

Expand Down
Loading
Loading