Skip to content

Commit 1f6987d

Browse files
authored
Revise SignalR documentation for .NET 8/9 workaround (#36035)
1 parent 4d5da2f commit 1f6987d

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

aspnetcore/blazor/fundamentals/signalr.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,25 +316,43 @@ app.MapBlazorHub(options =>
316316
});
317317
```
318318

319-
<!-- UPDATE 10.0 The following is scheduled for a fix in .NET 10 -->
319+
<!-- UPDATE 10.0 - The following is scheduled for a fix in .NET 10.
320+
Tracked by: https://github.com/dotnet/aspnetcore/issues/63520 -->
320321

321-
Configuring the hub used by <xref:Microsoft.AspNetCore.Builder.ServerRazorComponentsEndpointConventionBuilderExtensions.AddInteractiveServerRenderMode%2A> with <xref:Microsoft.AspNetCore.Builder.ComponentEndpointRouteBuilderExtensions.MapBlazorHub%2A> fails with an `AmbiguousMatchException`:
322+
Configuring the hub used by <xref:Microsoft.AspNetCore.Builder.ServerRazorComponentsEndpointConventionBuilderExtensions.AddInteractiveServerRenderMode%2A> with <xref:Microsoft.AspNetCore.Builder.ComponentEndpointRouteBuilderExtensions.MapBlazorHub%2A> fails with an <xref:System.Reflection.AmbiguousMatchException>:
322323

323324
> :::no-loc text="Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints.":::
324325
325-
To workaround the problem for apps targeting .NET 8, give the custom-configured Blazor hub higher precedence using the <xref:Microsoft.AspNetCore.Builder.RoutingEndpointConventionBuilderExtensions.WithOrder%2A> method:
326+
To workaround the problem for apps targeting .NET 8/9, take the following approach.
327+
328+
At the top of the `Program` file, add a `using` statement for <xref:Microsoft.AspNetCore.Http.Connections?displayProperty=fullName>:
326329

327330
```csharp
328-
app.MapBlazorHub(options =>
329-
{
330-
options.CloseOnAuthenticationExpiration = true;
331-
}).WithOrder(-1);
331+
using Microsoft.AspNetCore.Http.Connections;
332+
```
333+
334+
Where <xref:Microsoft.AspNetCore.Builder.RazorComponentsEndpointRouteBuilderExtensions.MapRazorComponents%2A> is called, chain the following endpoint convention to the <xref:Microsoft.AspNetCore.Builder.RazorComponentsEndpointConventionBuilder>:
335+
336+
```csharp
337+
app.MapRazorComponents<App>()
338+
.AddInteractiveServerRenderMode()
339+
.Add(e =>
340+
{
341+
var metadata = e.Metadata;
342+
var dispatcherOptions = metadata.OfType<HttpConnectionDispatcherOptions>().FirstOrDefault();
343+
344+
if (dispatcherOptions != null)
345+
{
346+
dispatcherOptions.CloseOnAuthenticationExpiration = true;
347+
}
348+
});
332349
```
333350

334351
For more information, see the following resources:
335352

336353
* [MapBlazorHub configuration in NET8 throws a The request matched multiple endpoints exception (`dotnet/aspnetcore` #51698)](https://github.com/dotnet/aspnetcore/issues/51698#issuecomment-1984340954)
337354
* [Attempts to map multiple blazor entry points with MapBlazorHub causes Ambiguous Route Error. This worked with net7 (`dotnet/aspnetcore` #52156)](https://github.com/dotnet/aspnetcore/issues/52156#issuecomment-1984503178)
355+
* [[Blazor] Provide access to the underlying SignalR HttpConnectionDispatcherOptions in AddInteractiveServerRenderMode (`dotnet/aspnetcore` #63520)](https://github.com/dotnet/aspnetcore/issues/63520)
338356

339357
:::moniker-end
340358

0 commit comments

Comments
 (0)