Skip to content

Commit 092abea

Browse files
Revise SignalR hub path and base path configuration examples - current examples are incomplete (#36541)
1 parent 948decd commit 092abea

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

aspnetcore/blazor/host-and-deploy/app-base-path.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,33 @@ For the second option, which is the usual approach taken, the app sets the base
7676

7777
## Server-side Blazor
7878

79-
Map the SignalR hub of a server-side Blazor app by passing the path to <xref:Microsoft.AspNetCore.Builder.ComponentEndpointRouteBuilderExtensions.MapBlazorHub%2A> in the `Program` file:
79+
Map the SignalR hub of a server-side Blazor app by passing the path to <xref:Microsoft.AspNetCore.Builder.ComponentEndpointRouteBuilderExtensions.MapBlazorHub%2A> in the `Program` file. The default Blazor hub path is `/_blazor`, and the following example sets the base path of the default hub to `base/path`:
8080

8181
```csharp
82-
app.MapBlazorHub("base/path");
82+
app.MapBlazorHub("base/path/_blazor");
8383
```
8484

8585
The benefit of using <xref:Microsoft.AspNetCore.Builder.ComponentEndpointRouteBuilderExtensions.MapBlazorHub%2A> is that you can map patterns, such as `"{tenant}"` and not just concrete paths.
8686

8787
You can also map the SignalR hub when the app is in a virtual folder with a [branched middleware pipeline](xref:fundamentals/middleware/index#branch-the-middleware-pipeline). In the following example, requests to `/base/path/` are handled by Blazor's SignalR hub:
8888

8989
```csharp
90-
app.Map("/base/path/", subapp => {
91-
subapp.UsePathBase("/base/path/");
90+
app.Map("/base/path", subapp => {
91+
subapp.UsePathBase("/base/path");
9292
subapp.UseRouting();
93-
subapp.UseEndpoints(endpoints => endpoints.MapBlazorHub());
93+
subapp.UseAntiforgery();
94+
subapp.UseEndpoints(endpoints => {
95+
endpoints.MapBlazorHub("/base/path/_blazor");
96+
endpoints.MapStaticAssets();
97+
endpoints.MapRazorComponents<App>()
98+
.AddInteractiveServerRenderMode();
99+
});
94100
});
95101
```
96102

103+
> [!NOTE]
104+
> The default Blazor hub path is `/_blazor`.
105+
97106
Configure the `<base>` tag, per the guidance in the [Configure the app base path](#configure-the-app-base-path) section.
98107

99108
:::moniker range="< aspnetcore-8.0"
@@ -144,17 +153,17 @@ In many hosting scenarios, the relative URL path to the app is the root of the a
144153
> [!NOTE]
145154
> In some hosting scenarios, such as GitHub Pages and IIS sub-apps, the app base path must be set to the server's relative URL path of the app.
146155
147-
* In a server-side Blazor app, use ***either*** of the following approaches:
156+
* In a server-side Blazor app, use the following approach:
148157

149-
* Option 1: Use the `<base>` tag to set the app's base path ([location of `<head>` content](xref:blazor/project-structure#location-of-head-and-body-content)):
158+
* Use the `<base>` tag to set the app's base path ([location of `<head>` content](xref:blazor/project-structure#location-of-head-and-body-content)):
150159

151160
```html
152161
<base href="/CoolApp/">
153162
```
154163

155164
**The trailing slash is required.**
156165

157-
* Option 2: Call <xref:Microsoft.AspNetCore.Builder.UsePathBaseExtensions.UsePathBase%2A> ***first*** in the app's request processing pipeline (`Program.cs`) immediately after the <xref:Microsoft.AspNetCore.Builder.WebApplicationBuilder> is built (`builder.Build()`) to configure the base path for any following middleware that interacts with the request path:
166+
* Call <xref:Microsoft.AspNetCore.Builder.UsePathBaseExtensions.UsePathBase%2A> ***first*** in the app's request processing pipeline (`Program.cs`) immediately after the <xref:Microsoft.AspNetCore.Builder.WebApplicationBuilder> is built (`builder.Build()`) to configure the base path for any following middleware that interacts with the request path:
158167

159168
```csharp
160169
app.UsePathBase("/CoolApp");

0 commit comments

Comments
 (0)