diff --git a/src/Components/Server/src/Builder/ServerComponentsEndpointOptions.cs b/src/Components/Server/src/Builder/ServerComponentsEndpointOptions.cs index 6cccf9db1656..7567b3410a4a 100644 --- a/src/Components/Server/src/Builder/ServerComponentsEndpointOptions.cs +++ b/src/Components/Server/src/Builder/ServerComponentsEndpointOptions.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Connections; namespace Microsoft.AspNetCore.Components.Server; @@ -53,4 +54,13 @@ public class ServerComponentsEndpointOptions /// defined in will be applied. /// public Func? ConfigureWebSocketAcceptContext { get; set; } + + /// + /// Gets or sets a callback to configure the used by the SignalR connection. + /// + /// + /// This allows configuring options such as , + /// transport options, authorization data, and other connection-level settings. + /// + public Action? ConfigureConnection { get; set; } } diff --git a/src/Components/Server/src/DependencyInjection/ServerRazorComponentsBuilderExtensions.cs b/src/Components/Server/src/DependencyInjection/ServerRazorComponentsBuilderExtensions.cs index 9b151b880c3d..3e6e08c45fa1 100644 --- a/src/Components/Server/src/DependencyInjection/ServerRazorComponentsBuilderExtensions.cs +++ b/src/Components/Server/src/DependencyInjection/ServerRazorComponentsBuilderExtensions.cs @@ -69,7 +69,10 @@ public override IEnumerable GetEndpointBuilders( } var endpointRouteBuilder = new EndpointRouteBuilder(Services, applicationBuilder); - var hub = endpointRouteBuilder.MapBlazorHub("/_blazor"); + var serverRenderMode = (InternalServerRenderMode)renderMode; + var hub = serverRenderMode.Options?.ConfigureConnection is not null + ? endpointRouteBuilder.MapBlazorHub("/_blazor", serverRenderMode.Options.ConfigureConnection) + : endpointRouteBuilder.MapBlazorHub("/_blazor"); if (renderMode is InternalServerRenderMode { Options.ConfigureWebSocketAcceptContext: var configureConnection, Options.DisableWebSocketCompression: var disableCompression } && (configureConnection is not null || !disableCompression)) diff --git a/src/Components/Server/src/PublicAPI.Unshipped.txt b/src/Components/Server/src/PublicAPI.Unshipped.txt index 7dc5c58110bf..203d8131cb73 100644 --- a/src/Components/Server/src/PublicAPI.Unshipped.txt +++ b/src/Components/Server/src/PublicAPI.Unshipped.txt @@ -1 +1,3 @@ #nullable enable +Microsoft.AspNetCore.Components.Server.ServerComponentsEndpointOptions.ConfigureConnection.get -> System.Action? +Microsoft.AspNetCore.Components.Server.ServerComponentsEndpointOptions.ConfigureConnection.set -> void