Skip to content

Commit 88adf95

Browse files
authored
Start Blazor circuit with custom URL (#34404)
1 parent 261ab6a commit 88adf95

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

aspnetcore/blazor/fundamentals/signalr.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,61 @@ Use a <xref:Microsoft.AspNetCore.Components.Server.Circuits.CircuitHandler> to c
14521452

14531453
:::moniker-end
14541454

1455+
## Start the SignalR circuit at a different URL
1456+
1457+
Prevent automatically starting the app by adding `autostart="false"` to the Blazor `<script>` tag ([location of the Blazor start script](xref:blazor/project-structure#location-of-the-blazor-script)). Manually establish the circuit URL using `Blazor.start`. The following examples use the path `/signalr`.
1458+
1459+
:::moniker range=">= aspnetcore-8.0"
1460+
1461+
Blazor Web Apps:
1462+
1463+
```diff
1464+
- <script src="_framework/blazor.web.js"></script>
1465+
+ <script src="_framework/blazor.web.js" autostart="false"></script>
1466+
+ <script>
1467+
+ Blazor.start({
1468+
+ circuit: {
1469+
+ configureSignalR: builder => builder.withUrl("/signalr")
1470+
+ },
1471+
+ });
1472+
+ </script>
1473+
```
1474+
1475+
Blazor Server:
1476+
1477+
:::moniker-end
1478+
1479+
```diff
1480+
- <script src="_framework/blazor.server.js"></script>
1481+
+ <script src="_framework/blazor.server.js" autostart="false"></script>
1482+
+ <script>
1483+
+ Blazor.start({
1484+
+ configureSignalR: builder => builder.withUrl("/signalr")
1485+
+ });
1486+
+ </script>
1487+
```
1488+
1489+
Add the following <xref:Microsoft.AspNetCore.Builder.ComponentEndpointRouteBuilderExtensions.MapBlazorHub%2A> call with the hub path to the middleware processing pipeline in the server app's `Program` file.
1490+
1491+
:::moniker range=">= aspnetcore-8.0"
1492+
1493+
Blazor Web Apps:
1494+
1495+
```csharp
1496+
app.MapBlazorHub("/signalr");
1497+
```
1498+
1499+
Blazor Server:
1500+
1501+
:::moniker-end
1502+
1503+
Leave the existing call to <xref:Microsoft.AspNetCore.Builder.ComponentEndpointRouteBuilderExtensions.MapBlazorHub%2A> in the file and add a new call to <xref:Microsoft.AspNetCore.Builder.ComponentEndpointRouteBuilderExtensions.MapBlazorHub%2A> with the path:
1504+
1505+
```diff
1506+
app.MapBlazorHub();
1507+
+ app.MapBlazorHub("/signalr");
1508+
```
1509+
14551510
## `IHttpContextAccessor`/`HttpContext`
14561511

14571512
[!INCLUDE[](~/blazor/security/includes/httpcontext.md)]

0 commit comments

Comments
 (0)