Skip to content

Commit 4316d23

Browse files
github-actions[bot]lewingCopilotCopilot
authored
[release/11.0-preview6] Fix Blazor WASM Standalone HTTPS failure with Gateway (#67565)
* Fix Blazor WASM Standalone HTTPS failure with Gateway The Blazor Gateway replaced the DevServer in #66729, switching from Host.CreateDefaultBuilder (which auto-configures Kestrel HTTPS) to WebApplication.CreateSlimBuilder (which does not). This caused 'blazorwasm' template projects to throw InvalidOperationException when using an https:// launch profile URL. Add UseKestrelHttpsConfiguration() to BlazorGateway.BuildWebHost so Kestrel can bind HTTPS endpoints. Fixes #67484 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add Gateway HTTPS regression test Co-authored-by: lewing <24063+lewing@users.noreply.github.com> * Assert Gateway binds HTTPS in regression test Co-authored-by: lewing <24063+lewing@users.noreply.github.com> --------- Co-authored-by: Larry Ewing <lewing@gmail.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: lewing <24063+lewing@users.noreply.github.com>
1 parent 6bd759a commit 4316d23

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/Components/Gateway/src/BlazorGateway.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ internal static WebApplication BuildWebHost(WebApplicationBuilder builder)
3939

4040
builder.Services.AddServiceDiscovery();
4141

42+
builder.WebHost.UseKestrelHttpsConfiguration();
4243
builder.WebHost.UseStaticWebAssets();
4344

4445
var appConfigs = builder.Configuration.GetSection("ClientApps")

src/Components/Gateway/test/BlazorGatewayTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,24 @@ public async Task ClientApps_ConfigEndpoint_ReturnsConfiguredJson()
198198
Assert.Equal(json, body, ignoreLineEndingDifferences: true);
199199
}
200200

201+
[Fact]
202+
public async Task BuildWebHost_StartsWithHttpsUrl_WhenKestrelCertificateConfigured()
203+
{
204+
var testCertificatePath = Path.Combine(AppContext.BaseDirectory, "shared", "TestCertificates", "testCert.pfx");
205+
var builder = WebApplication.CreateSlimBuilder(new[] { "--urls", "https://127.0.0.1:0" });
206+
builder.Configuration.AddInMemoryCollection(new Dictionary<string, string?>
207+
{
208+
["Kestrel:Certificates:Default:Path"] = testCertificatePath,
209+
["Kestrel:Certificates:Default:Password"] = "testPassword",
210+
});
211+
212+
await using var app = BlazorGateway.BuildWebHost(builder);
213+
214+
await app.StartAsync();
215+
216+
Assert.Contains(app.Urls, address => address.StartsWith("https://127.0.0.1:", StringComparison.Ordinal));
217+
}
218+
201219
private static bool IsRedirect(HttpStatusCode status) =>
202220
status is HttpStatusCode.MovedPermanently
203221
or HttpStatusCode.Found

src/Components/Gateway/test/Microsoft.AspNetCore.Components.Gateway.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<Reference Include="Microsoft.Extensions.ServiceDiscovery" />
2222
<Reference Include="Microsoft.Extensions.ServiceDiscovery.Yarp" />
2323
<Reference Include="Yarp.ReverseProxy" />
24+
<Content Include="$(SharedSourceRoot)TestCertificates\*.pfx" LinkBase="shared\TestCertificates" CopyToOutputDirectory="PreserveNewest" />
2425
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="$(OpenTelemetryExporterOpenTelemetryProtocolVersion)" />
2526
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="$(OpenTelemetryExtensionsHostingVersion)" />
2627
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="$(OpenTelemetryInstrumentationAspNetCoreVersion)" />

0 commit comments

Comments
 (0)