Skip to content

[Pre ?] Blazor startup options format #34660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 13 additions & 1 deletion aspnetcore/blazor/fundamentals/environments.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ For general guidance on ASP.NET Core app configuration, see <xref:fundamentals/e

The following example starts Blazor in the `Staging` environment if the hostname includes `localhost`. Otherwise, the environment is set to its default value.

:::moniker range=">= aspnetcore-8.0"
:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Blazor Web App:

:::moniker-end

:::moniker range=">= aspnetcore-8.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -92,10 +96,16 @@ Blazor Web App:
> [!NOTE]
> For Blazor Web Apps that set the `webAssembly` > `environment` property in `Blazor.start` configuration, it's wise to match the server-side environment to the environment set on the `environment` property. Otherwise, prerendering on the server will operate under a different environment than rendering on the client, which results in arbitrary effects. For general guidance on setting the environment for a Blazor Web App, see <xref:fundamentals/environments>.

:::moniker-end

:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Standalone Blazor WebAssembly:

:::moniker-end

:::moniker range="< aspnetcore-10.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -109,6 +119,8 @@ Standalone Blazor WebAssembly:
</script>
```

:::moniker-end

**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see <xref:blazor/project-structure#location-of-the-blazor-script>.

Using the `environment` property overrides the environment set by the [`Blazor-Environment` header](#set-the-client-side-environment-via-header).
Expand Down
28 changes: 26 additions & 2 deletions aspnetcore/blazor/fundamentals/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,14 @@ For the `configureLogging` log level value, pass the argument as either the stri

Example 1: Set the <xref:Microsoft.Extensions.Logging.LogLevel.Information> log level with a string value.

:::moniker range=">= aspnetcore-8.0"
:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Blazor Web App:

:::moniker-end

:::moniker range=">= aspnetcore-8.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -687,10 +691,16 @@ Blazor Web App:
</script>
```

:::moniker-end

:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Blazor Server:

:::moniker-end

:::moniker range="< aspnetcore-10.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -702,14 +712,20 @@ Blazor Server:
</script>
```

:::moniker-end

**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see <xref:blazor/project-structure#location-of-the-blazor-script>.

Example 2: Set the <xref:Microsoft.Extensions.Logging.LogLevel.Information> log level with an integer value.

:::moniker range=">= aspnetcore-8.0"
:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Blazor Web App:

:::moniker-end

:::moniker range=">= aspnetcore-8.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -723,10 +739,16 @@ Blazor Web App:
</script>
```

:::moniker-end

:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Blazor Server:

:::moniker-end

:::moniker range="< aspnetcore-10.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -738,6 +760,8 @@ Blazor Server:
</script>
```

:::moniker-end

**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see <xref:blazor/project-structure#location-of-the-blazor-script>.

> [!NOTE]
Expand Down
106 changes: 96 additions & 10 deletions aspnetcore/blazor/fundamentals/signalr.md
Original file line number Diff line number Diff line change
Expand Up @@ -885,8 +885,16 @@ Configure the following values for the client:

The following example for the `App.razor` file (Blazor Web App) shows the assignment of default values.

:::moniker-end

:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Blazor Web App:

:::moniker-end

:::moniker range=">= aspnetcore-8.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -902,8 +910,16 @@ Blazor Web App:

The following example for the `Pages/_Host.cshtml` file (Blazor Server, all versions except ASP.NET Core in .NET 6) or `Pages/_Layout.cshtml` file (Blazor Server, ASP.NET Core in .NET 6).

:::moniker-end

:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Blazor Server:

:::moniker-end

:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -915,6 +931,10 @@ Blazor Server:
</script>
```

:::moniker-end

:::moniker range=">= aspnetcore-8.0"

**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script and the path to use, see <xref:blazor/project-structure#location-of-the-blazor-script>.

When creating a hub connection in a component, set the <xref:Microsoft.AspNetCore.SignalR.Client.HubConnection.ServerTimeout> (default: 30 seconds) and <xref:Microsoft.AspNetCore.SignalR.Client.HubConnection.KeepAliveInterval> (default: 15 seconds) on the <xref:Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilder>. Set the <xref:Microsoft.AspNetCore.SignalR.Client.HubConnection.HandshakeTimeout> (default: 15 seconds) on the built <xref:Microsoft.AspNetCore.SignalR.Client.HubConnection>. The following example shows the assignment of default values:
Expand Down Expand Up @@ -1010,10 +1030,14 @@ To modify the connection events, register callbacks for the following connection

**Both `onConnectionDown` and `onConnectionUp` must be specified.**

:::moniker range=">= aspnetcore-8.0"
:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Blazor Web App:

:::moniker-end

:::moniker range=">= aspnetcore-8.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -1028,10 +1052,16 @@ Blazor Web App:
</script>
```

:::moniker-end

:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Blazor Server:

:::moniker-end

:::moniker range="< aspnetcore-10.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -1044,6 +1074,8 @@ Blazor Server:
</script>
```

:::moniker-end

**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script and the path to use, see <xref:blazor/project-structure#location-of-the-blazor-script>.

:::moniker range=">= aspnetcore-7.0"
Expand Down Expand Up @@ -1080,10 +1112,14 @@ Create the following `wwwroot/boot.js` file.

:::moniker-end

:::moniker range=">= aspnetcore-8.0"
:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Blazor Web App:

:::moniker-end

:::moniker range=">= aspnetcore-8.0"

```javascript
(() => {
const maximumRetryCount = 3;
Expand Down Expand Up @@ -1148,11 +1184,15 @@ Blazor Web App:
})();
```

:::moniker-end

:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Blazor Server:

:::moniker-end

:::moniker range=">= aspnetcore-7.0"
:::moniker range=">= aspnetcore-7.0 < aspnetcore-10.0"

```javascript
(() => {
Expand Down Expand Up @@ -1224,10 +1264,14 @@ For more information on Blazor startup, see <xref:blazor/fundamentals/startup>.

To adjust the reconnection retry count and interval, set the number of retries (`maxRetries`) and period in milliseconds permitted for each retry attempt (`retryIntervalMilliseconds`).

:::moniker range=">= aspnetcore-8.0"
:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Blazor Web App:

:::moniker-end

:::moniker range=">= aspnetcore-8.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -1242,10 +1286,16 @@ Blazor Web App:
</script>
```

:::moniker-end

:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Blazor Server:

:::moniker-end

:::moniker range="< aspnetcore-10.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -1258,6 +1308,8 @@ Blazor Server:
</script>
```

:::moniker-end

**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script and the path to use, see <xref:blazor/project-structure#location-of-the-blazor-script>.

:::moniker range=">= aspnetcore-9.0"
Expand Down Expand Up @@ -1369,8 +1421,16 @@ The server timeout can be increased, and the Keep-Alive interval can remain the

In the following [startup configuration](xref:blazor/fundamentals/startup) example ([location of the Blazor script](xref:blazor/project-structure#location-of-the-blazor-script)), a custom value of 60 seconds is used for the server timeout. The Keep-Alive interval (`withKeepAliveInterval`) isn't set and uses its default value of 15 seconds.

:::moniker-end

:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Blazor Web App:

:::moniker-end

:::moniker range=">= aspnetcore-8.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -1384,8 +1444,16 @@ Blazor Web App:
</script>
```

:::moniker-end

:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Blazor Server:

:::moniker-end

:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

```html
<script src="{BLAZOR SCRIPT}" autostart="false"></script>
<script>
Expand All @@ -1397,6 +1465,10 @@ Blazor Server:
</script>
```

:::moniker-end

:::moniker range=">= aspnetcore-8.0"

When creating a hub connection in a component, set the server timeout (<xref:Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderExtensions.WithServerTimeout%2A>, default: 30 seconds) on the <xref:Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilder>. Set the <xref:Microsoft.AspNetCore.SignalR.Client.HubConnection.HandshakeTimeout> (default: 15 seconds) on the built <xref:Microsoft.AspNetCore.SignalR.Client.HubConnection>. Confirm that the timeouts are at least double the Keep-Alive interval (<xref:Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilderExtensions.WithKeepAliveInterval%2A>/<xref:Microsoft.AspNetCore.SignalR.Client.HubConnection.KeepAliveInterval>) and that the Keep-Alive value matches between server and client.

The following example is based on the `Index` component in the [SignalR with Blazor tutorial](xref:blazor/tutorials/signalr-blazor). The server timeout is increased to 60 seconds, and the handshake timeout is increased to 30 seconds. The Keep-Alive interval isn't set and uses its default value of 15 seconds.
Expand Down Expand Up @@ -1535,13 +1607,17 @@ Use a <xref:Microsoft.AspNetCore.Components.Server.Circuits.CircuitHandler> to c

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

:::moniker range=">= aspnetcore-8.0"
:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Blazor Web Apps:
Blazor Web App:

:::moniker-end

:::moniker range=">= aspnetcore-8.0"

```diff
- <script src="_framework/blazor.web.js"></script>
+ <script src="_framework/blazor.web.js" autostart="false"></script>
- <script src="{BLAZOR SCRIPT}"></script>
+ <script src="{BLAZOR SCRIPT}" autostart="false"></script>
+ <script>
+ Blazor.start({
+ circuit: {
Expand All @@ -1551,20 +1627,30 @@ Blazor Web Apps:
+ </script>
```

:::moniker-end

:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0"

Blazor Server:

:::moniker-end

:::moniker range="< aspnetcore-10.0"

```diff
- <script src="_framework/blazor.server.js"></script>
+ <script src="_framework/blazor.server.js" autostart="false"></script>
- <script src="{BLAZOR SCRIPT}"></script>
+ <script src="{BLAZOR SCRIPT}" autostart="false"></script>
+ <script>
+ Blazor.start({
+ configureSignalR: builder => builder.withUrl("/signalr")
+ });
+ </script>
```

:::moniker-end

**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see <xref:blazor/project-structure#location-of-the-blazor-script>.

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.

:::moniker range=">= aspnetcore-8.0"
Expand Down
Loading