From 0bd34c33ba07c54a3c1acb5bef69138cdd3d2ad6 Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Tue, 6 Jan 2026 09:04:34 -0500 Subject: [PATCH] [11.0 P1] Blazor startup options format --- .../blazor/fundamentals/environments.md | 16 +- aspnetcore/blazor/fundamentals/logging.md | 30 +++- aspnetcore/blazor/fundamentals/signalr.md | 158 ++++++++++++++++-- aspnetcore/blazor/fundamentals/startup.md | 78 ++++++++- .../blazor/globalization-localization.md | 14 +- .../host-and-deploy/webassembly/index.md | 14 +- 6 files changed, 284 insertions(+), 26 deletions(-) diff --git a/aspnetcore/blazor/fundamentals/environments.md b/aspnetcore/blazor/fundamentals/environments.md index 373a1cf17a09..93d199b5947e 100644 --- a/aspnetcore/blazor/fundamentals/environments.md +++ b/aspnetcore/blazor/fundamentals/environments.md @@ -124,10 +124,14 @@ For general guidance on ASP.NET Core app configuration, see ``` +:::moniker-end + +:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0" + Blazor Server: :::moniker-end +:::moniker range="< aspnetcore-11.0" + ```html ``` +:::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 . Example 2: Set the log level with an integer value. -:::moniker range=">= aspnetcore-8.0" +:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0" Blazor Web App: +:::moniker-end + +:::moniker range=">= aspnetcore-8.0" + ```html ``` +**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see . + +:::moniker-end + +:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0" + Blazor Server: :::moniker-end +:::moniker range="< aspnetcore-11.0" + ```html ``` +**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see . + 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-11.0" + Blazor Server: ```html @@ -929,7 +943,11 @@ Blazor Server: ``` -**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 . +**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see . + +:::moniker-end + +:::moniker range=">= aspnetcore-8.0" When creating a hub connection in a component, set the (default: 30 seconds) and (default: 15 seconds) on the . Set the (default: 15 seconds) on the built . The following example shows the assignment of default values: @@ -977,7 +995,7 @@ The following example for the `Pages/_Host.cshtml` file (Blazor Server, all vers ``` -**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 . +**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see . When creating a hub connection in a component, set the (default: 30 seconds), (default: 15 seconds), and (default: 15 seconds) on the built . The following example shows the assignment of default values: @@ -1014,10 +1032,14 @@ For more information, see the *Global deployment and connection failures* sectio 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-11.0" Blazor Web App: +:::moniker-end + +:::moniker range=">= aspnetcore-8.0" + ```html ``` +**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see . + +:::moniker-end + +:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0" + Blazor Server: :::moniker-end +:::moniker range="< aspnetcore-11.0" + ```html ``` -**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 . +**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see . + +:::moniker-end :::moniker range=">= aspnetcore-9.0" @@ -1060,6 +1092,16 @@ The default reconnect timing uses a computed backoff strategy. The first several Customize the retry interval behavior by specifying a function to compute the retry interval. In the following exponential backoff example, the number of previous reconnection attempts is multiplied by 1,000 ms to calculate the retry interval. When the count of previous attempts to reconnect (`previousAttempts`) is greater than the maximum retry limit (`maxRetries`), `null` is assigned to the retry interval (`retryIntervalMilliseconds`) to cease further reconnection attempts: +:::moniker-end + +:::moniker range=">= aspnetcore-9.0 < aspnetcore-11.0" + +Blazor Web App: + +:::moniker-end + +:::moniker range=">= aspnetcore-9.0" + ```javascript Blazor.start({ circuit: { @@ -1071,8 +1113,37 @@ Blazor.start({ }); ``` +:::moniker-end + +:::moniker range=">= aspnetcore-9.0 < aspnetcore-11.0" + +Blazor Server: + +```javascript +Blazor.start({ + reconnectionOptions: { + retryIntervalMilliseconds: (previousAttempts, maxRetries) => + previousAttempts >= maxRetries ? null : previousAttempts * 1000 + }, +}); +``` + +:::moniker-end + +:::moniker range=">= aspnetcore-9.0" + An alternative is to specify the exact sequence of retry intervals. After the last specified retry interval, retries stop because the `retryIntervalMilliseconds` function returns `undefined`: +:::moniker-end + +:::moniker range=">= aspnetcore-9.0 < aspnetcore-11.0" + +Blazor Web App: + +:::moniker-end + +:::moniker range=">= aspnetcore-9.0" + ```javascript Blazor.start({ circuit: { @@ -1086,8 +1157,27 @@ Blazor.start({ :::moniker-end +:::moniker range=">= aspnetcore-9.0 < aspnetcore-11.0" + +Blazor Server: + +```javascript +Blazor.start({ + reconnectionOptions: { + retryIntervalMilliseconds: + Array.prototype.at.bind([0, 1000, 2000, 5000, 10000, 15000, 30000]), + }, +}); +``` + +:::moniker-end + +:::moniker range=">= aspnetcore-9.0" + For more information on Blazor startup, see . +:::moniker-end + :::moniker range=">= aspnetcore-6.0" ## Control when the reconnection UI appears @@ -1159,8 +1249,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-11.0" + Blazor Web App: +:::moniker-end + +:::moniker range=">= aspnetcore-8.0" + ```html ``` +:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0" + Blazor Server: ```html @@ -1187,6 +1287,10 @@ Blazor Server: ``` +:::moniker-end + +:::moniker range=">= aspnetcore-8.0" + When creating a hub connection in a component, set the server timeout (, default: 30 seconds) on the . Set the (default: 15 seconds) on the built . Confirm that the timeouts are at least double the Keep-Alive interval (/) 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. @@ -1273,10 +1377,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-11.0" Blazor Web App: +:::moniker-end + +:::moniker range=">= aspnetcore-8.0" + ```html ``` +**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see . + +:::moniker-end + +:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0" + Blazor Server: :::moniker-end +:::moniker range="< aspnetcore-11.0" + ```html ``` -**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 . +**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see . + +:::moniker-end :::moniker range=">= aspnetcore-7.0" @@ -1347,16 +1465,20 @@ The default reconnection behavior requires the user to take manual action to ref ``` -**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 . +**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see . Create the following `wwwroot/boot.js` file. :::moniker-end -:::moniker range=">= aspnetcore-8.0" +:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0" Blazor Web App: +:::moniker-end + +:::moniker range=">= aspnetcore-8.0" + ```javascript (() => { const maximumRetryCount = 3; @@ -1421,11 +1543,11 @@ Blazor Web App: })(); ``` -Blazor Server: - :::moniker-end -:::moniker range=">= aspnetcore-7.0" +:::moniker range=">= aspnetcore-7.0 < aspnetcore-11.0" + +Blazor Server: ```javascript (() => { @@ -1559,10 +1681,14 @@ Use a to c Prevent automatically starting the app by adding `autostart="false"` to the Blazor ` + @@ -1575,10 +1701,16 @@ Blazor Web Apps: + ``` +:::moniker-end + +:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0" + Blazor Server: :::moniker-end +:::moniker range="< aspnetcore-11.0" + ```diff - + @@ -1589,6 +1721,8 @@ Blazor Server: + ``` +:::moniker-end + Add the following call with the hub path to the middleware processing pipeline in the server app's `Program` file. :::moniker range=">= aspnetcore-8.0" diff --git a/aspnetcore/blazor/fundamentals/startup.md b/aspnetcore/blazor/fundamentals/startup.md index 5736d5929557..e5144de1ab7e 100644 --- a/aspnetcore/blazor/fundamentals/startup.md +++ b/aspnetcore/blazor/fundamentals/startup.md @@ -22,9 +22,9 @@ For general guidance on ASP.NET Core app configuration for server-side developme The Blazor startup process is automatic and asynchronous via the Blazor script (`blazor.*.js`), where the `*` placeholder is: -* `web` for a Blazor Web App -* `server` for a Blazor Server app -* `webassembly` for a Blazor WebAssembly app +* `web` for a Blazor Web App. +* `server` for a Blazor Server app. +* `webassembly` for a Blazor WebAssembly app. :::moniker-end @@ -32,8 +32,8 @@ The Blazor startup process is automatic and asynchronous via the Blazor script ( The Blazor startup process is automatic and asynchronous via the Blazor script (`blazor.*.js`), where the `*` placeholder is: -* `server` for a Blazor Server app -* `webassembly` for a Blazor WebAssembly app +* `server` for a Blazor Server app. +* `webassembly` for a Blazor WebAssembly app. :::moniker-end @@ -41,10 +41,14 @@ For the location of the script, see ` tag. * Place a script that calls `Blazor.start()` after the Blazor ` ``` +**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see . + +:::moniker-end + +:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0" + Standalone Blazor WebAssembly and Blazor Server: :::moniker-end +:::moniker range="< aspnetcore-11.0" + * Add an `autostart="false"` attribute and value to the Blazor ` ``` +**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see . + +:::moniker-end + +:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0" + Standalone Blazor WebAssembly: :::moniker-end +:::moniker range="< aspnetcore-11.0" + ```html ``` +**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see . + +:::moniker-end + +:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0" + Standalone Blazor WebAssembly: :::moniker-end +:::moniker range="< aspnetcore-11.0" + ```html ``` +**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see . + +:::moniker-end + +:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0" + Standalone Blazor WebAssembly: ```html @@ -990,6 +1046,12 @@ Standalone Blazor WebAssembly: ``` +**In the preceding example, the `{BLAZOR SCRIPT}` placeholder is the Blazor script path and file name.** For the location of the script, see . + +:::moniker-end + +:::moniker range=">= aspnetcore-8.0" + > [!NOTE] > The .NET runtime instance can be accessed using the .NET WebAssembly Runtime API (`Blazor.runtime`). For example, the app's build configuration can be obtained using `Blazor.runtime.runtimeBuildInfo.buildConfiguration`. > diff --git a/aspnetcore/blazor/globalization-localization.md b/aspnetcore/blazor/globalization-localization.md index e31c45d4b351..807d3adff6da 100644 --- a/aspnetcore/blazor/globalization-localization.md +++ b/aspnetcore/blazor/globalization-localization.md @@ -368,10 +368,14 @@ Prevent Blazor autostart by adding `autostart="false"` to [Blazor's ` ``` +:::moniker-end + +:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0" + Standalone Blazor WebAssembly: :::moniker-end +:::moniker range="< aspnetcore-11.0" + ```html ``` +:::moniker-end + The value for `applicationCulture` must conform to the [BCP-47 language tag format](https://www.rfc-editor.org/info/bcp47). For more information on Blazor startup, see . An alternative to setting the culture Blazor's start option is to set the culture in C# code. Set and in the `Program` file to the same culture. diff --git a/aspnetcore/blazor/host-and-deploy/webassembly/index.md b/aspnetcore/blazor/host-and-deploy/webassembly/index.md index 9cc6b6e09084..59d19a630c30 100644 --- a/aspnetcore/blazor/host-and-deploy/webassembly/index.md +++ b/aspnetcore/blazor/host-and-deploy/webassembly/index.md @@ -118,10 +118,14 @@ In the `wwwroot/index.html` file, set `autostart` to `false` on Blazor's `` tag and before the closing `` tag, add the following JavaScript code ` ``` +:::moniker-end + +:::moniker range=">= aspnetcore-8.0 < aspnetcore-11.0" + Standalone Blazor WebAssembly: :::moniker-end +:::moniker range="< aspnetcore-11.0" + ```html ``` +:::moniker-end + For more information on loading boot resources, see . :::moniker range=">= aspnetcore-8.0"