Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions aspnetcore/blazor/host-and-deploy/app-base-path.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,33 @@ For the second option, which is the usual approach taken, the app sets the base

## Server-side Blazor

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:
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`:

```csharp
app.MapBlazorHub("base/path");
app.MapBlazorHub("base/path/_blazor");
```

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.

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:

```csharp
app.Map("/base/path/", subapp => {
subapp.UsePathBase("/base/path/");
app.Map("/base/path", subapp => {
subapp.UsePathBase("/base/path");
subapp.UseRouting();
subapp.UseEndpoints(endpoints => endpoints.MapBlazorHub());
subapp.UseAntiforgery();
subapp.UseEndpoints(endpoints => {
endpoints.MapBlazorHub("/base/path/_blazor");
endpoints.MapStaticAssets();
endpoints.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
});
});
```

> [!NOTE]
> The default Blazor hub path is `/_blazor`.

Configure the `<base>` tag, per the guidance in the [Configure the app base path](#configure-the-app-base-path) section.

:::moniker range="< aspnetcore-8.0"
Expand Down Expand Up @@ -144,17 +153,17 @@ In many hosting scenarios, the relative URL path to the app is the root of the a
> [!NOTE]
> 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.

* In a server-side Blazor app, use ***either*** of the following approaches:
* In a server-side Blazor app, use the following approach:

* 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)):
* 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)):

```html
<base href="/CoolApp/">
```

**The trailing slash is required.**

* 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:
* 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:

```csharp
app.UsePathBase("/CoolApp");
Expand Down