Skip to content

Version hosted WASM <8.0 #30253

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

Merged
merged 3 commits into from
Sep 7, 2023
Merged
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
4 changes: 4 additions & 0 deletions aspnetcore/blazor/call-web-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ public class TodoItem

For guidance on how to create a server-side web API, see <xref:tutorials/first-web-api>. For information on Cross-Origin Resource Sharing (CORS), see the *Cross-Origin Resource Sharing (CORS)* section later in this article.

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

The Blazor examples that demonstrate obtaining weather data from a server API are based on a hosted Blazor WebAssembly solution created from the [Blazor WebAssembly project template](xref:blazor/project-structure#blazor-webassembly).

:::moniker-end

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

<!-- UPDATE 8.0 Cross-link SSR and CSR -->
Expand Down
4 changes: 4 additions & 0 deletions aspnetcore/blazor/components/class-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,14 @@ For more information, see <xref:razor-pages/ui-class#create-an-rcl-with-static-a

:::moniker-end

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

## Supply components and static assets to multiple hosted Blazor apps

For more information, see <xref:blazor/host-and-deploy/multiple-hosted-webassembly>.

:::moniker-end

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

## Client-side browser compatibility analyzer
Expand Down
4 changes: 4 additions & 0 deletions aspnetcore/blazor/components/css-isolation.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ CSS isolation occurs at build time. Blazor rewrites CSS selectors to match marku
<link href="{ASSEMBLY NAME}.styles.css" rel="stylesheet">
```

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

The following example is from a hosted Blazor WebAssembly **:::no-loc text="Client":::** app. The app's assembly name is `BlazorSample.Client`, and the `<link>` is added by the Blazor WebAssembly project template when the project is created with the Hosted option (`-ho|--hosted` option using the .NET CLI or **ASP.NET Core Hosted** checkbox using Visual Studio):

```html
<link href="BlazorSample.Client.styles.css" rel="stylesheet">
```

:::moniker-end

Within the bundled file, each component is associated with a scope identifier. For each styled component, an HTML attribute is appended with the format `b-{STRING}`, where the `{STRING}` placeholder is a ten-character string generated by the framework. The identifier is unique for each app. In the rendered `Counter` component, Blazor appends a scope identifier to the `h1` element:

```html
Expand Down
4 changes: 2 additions & 2 deletions aspnetcore/blazor/components/lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Blazor apps that prerender their content on the server call <xref:Microsoft.AspN
the API for 'WebAssemblyPrerendered' might be different,
and cross-link 'client-side rendered (CSR)'. -->

To prevent developer code in <xref:Microsoft.AspNetCore.Components.ComponentBase.OnInitializedAsync%2A> from running twice when prerendering, see the [Stateful reconnection after prerendering](#stateful-reconnection-after-prerendering) section. Although the content in the section focuses on Blazor Web Apps and stateful SignalR *reconnection*, the scenario for prerendering client-side rendered (CSR) WebAssembly components or client-side components in hosted Blazor WebAssembly solutions (<xref:Microsoft.AspNetCore.Mvc.Rendering.RenderMode.WebAssemblyPrerendered>) involves similar conditions and approaches to prevent executing developer code twice. To preserve state during the execution of initialization code while prerendering, see <xref:blazor/components/prerendering-and-integration#persist-prerendered-state>.
To prevent developer code in <xref:Microsoft.AspNetCore.Components.ComponentBase.OnInitializedAsync%2A> from running twice when prerendering, see the [Stateful reconnection after prerendering](#stateful-reconnection-after-prerendering) section. The content in the section focuses on Blazor Web Apps and stateful SignalR *reconnection*. To preserve state during the execution of initialization code while prerendering, see <xref:blazor/components/prerendering-and-integration#persist-prerendered-state>.

:::moniker-end

Expand Down Expand Up @@ -409,7 +409,7 @@ For more information on the <xref:Microsoft.AspNetCore.Mvc.TagHelpers.ComponentT

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

Although the content in this section focuses on Blazor Web Apps and stateful SignalR *reconnection*, the scenario for prerendering client-side rendered (CSR) WebAssembly components or client-side components in hosted Blazor WebAssembly solutions (<xref:Microsoft.AspNetCore.Mvc.Rendering.RenderMode.WebAssemblyPrerendered>) involves similar conditions and approaches to prevent executing developer code twice. To preserve state during the execution of initialization code while prerendering, see <xref:blazor/components/prerendering-and-integration#persist-prerendered-state>.
The content in this section focuses on Blazor Web Apps and stateful SignalR *reconnection*. To preserve state during the execution of initialization code while prerendering, see <xref:blazor/components/prerendering-and-integration#persist-prerendered-state>.

:::moniker-end

Expand Down
40 changes: 31 additions & 9 deletions aspnetcore/blazor/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ For now, you *can't*:
* Break on unhandled exceptions.
* Hit breakpoints during app startup before the debug proxy is running. This includes breakpoints in `Program.cs` and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app.
* Debug in non-local scenarios (for example, [Windows Subsystem for Linux (WSL)](/windows/wsl/) or [Visual Studio Codespaces](https://visualstudio.microsoft.com/services/github-codespaces/)).
* Automatically rebuild the backend **:::no-loc text="Server":::** app of a hosted Blazor WebAssembly [solution](xref:blazor/tooling#visual-studio-solution-file-sln) during debugging, for example by running the app with [`dotnet watch run`](xref:tutorials/dotnet-watch).

* Debug in Firefox from Visual Studio.

:::moniker-end
Expand All @@ -62,7 +62,6 @@ For now, you *can't*:
* Break on unhandled exceptions.
* Hit breakpoints during app startup before the debug proxy is running. This includes breakpoints in `Program.cs` and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app.
* Debug in non-local scenarios (for example, [Windows Subsystem for Linux (WSL)](/windows/wsl/) or [Visual Studio Codespaces](https://visualstudio.microsoft.com/services/github-codespaces/)).
* Automatically rebuild the backend **:::no-loc text="Server":::** app of a hosted Blazor WebAssembly [solution](xref:blazor/tooling#visual-studio-solution-file-sln) during debugging, for example by running the app with [`dotnet watch run`](xref:tutorials/dotnet-watch).
* Use a [symbol server](xref:test/debug-aspnetcore-source) for debugging.

:::moniker-end
Expand Down Expand Up @@ -114,13 +113,19 @@ After opening a project in VS Code, you may receive a notification that addition

Standalone Blazor WebAssembly: [`Microsoft.AspNetCore.Components.WebAssembly.DevServer`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly.DevServer): Development server for use when building Blazor apps. Calls <xref:Microsoft.AspNetCore.Builder.WebAssemblyNetDebugProxyAppBuilderExtensions.UseWebAssemblyDebugging%2A?displayProperty=nameWithType> internally to add middleware for debugging Blazor WebAssembly apps inside Chromium developer tools.

<!-- UPDATE 8.0 Although this isn't going to be true
for hosted WASM, it might still be true for debugging
client-side of BWAs. Will need to sort this out later.

Hosted Blazor WebAssembly:

* **:::no-loc text="Client":::** project: [`Microsoft.AspNetCore.Components.WebAssembly.DevServer`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly.DevServer): Development server for use when building Blazor apps. Calls <xref:Microsoft.AspNetCore.Builder.WebAssemblyNetDebugProxyAppBuilderExtensions.UseWebAssemblyDebugging%2A?displayProperty=nameWithType> internally to add middleware for debugging Blazor WebAssembly apps inside Chromium developer tools.
* **:::no-loc text="Server":::** project: [`Microsoft.AspNetCore.Components.WebAssembly.Server`](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly.Server): References an internal package ([`Microsoft.NETCore.BrowserDebugHost.Transport`](https://github.com/dotnet/runtime/blob/main/src/mono/nuget/Microsoft.NETCore.BrowserDebugHost.Transport/Microsoft.NETCore.BrowserDebugHost.Transport.pkgproj)) for assemblies that share the browser debug host.

[!INCLUDE[](~/includes/package-reference.md)]

-->

## Debug a standalone Blazor WebAssembly app

To enable debugging for an existing Blazor WebAssembly app, update the `launchSettings.json` file in the startup project to include the following `inspectUri` property in each launch profile:
Expand All @@ -142,7 +147,9 @@ The placeholder values for the WebSocket protocol (`wsProtocol`), host (`url.hos

# [Visual Studio](#tab/visual-studio)

To debug a Blazor WebAssembly app in Visual Studio:
<!-- UPDATE 8.0 Need to update this for BWA. There's an issue
to track updates for this article at
https://github.com/dotnet/AspNetCore.Docs/issues/30170

1. Create a new hosted Blazor WebAssembly [solution](xref:blazor/tooling#visual-studio-solution-file-sln).
1. With the **:::no-loc text="Server":::** project selected in **Solution Explorer**, press <kbd>F5</kbd> to run the app in the debugger.
Expand Down Expand Up @@ -174,8 +181,12 @@ While debugging a Blazor WebAssembly app, you can also debug server code:

<h2 id="vscode">Debug standalone Blazor WebAssembly</h2>

-->

For information on configuring VS Code assets in the `.vscode` folder, see the **Linux** operating system guidance in <xref:blazor/tooling>.

To debug a Blazor WebAssembly app in Visual Studio:

1. Open the standalone Blazor WebAssembly app in VS Code.

You may receive a notification that additional setup is required to enable debugging:
Expand Down Expand Up @@ -225,6 +236,10 @@ For information on configuring VS Code assets in the `.vscode` folder, see the *
> [!NOTE]
> Breakpoints are **not** hit during app startup before the debug proxy is running. This includes breakpoints in `Program.cs` and breakpoints in the [`OnInitialized{Async}` lifecycle methods](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) of components that are loaded by the first page requested from the app.

<!-- UPDATE 8.0 Need to update this for BWA. There's an issue
to track updates for this article at
https://github.com/dotnet/AspNetCore.Docs/issues/30170

## Debug hosted Blazor WebAssembly

For guidance on configuring VS Code assets in the `.vscode` folder and where to place the `.vscode` folder in the [solution](xref:blazor/tooling#visual-studio-solution-file-sln), see the **Linux** operating system guidance in <xref:blazor/tooling?pivots=linux>.
Expand Down Expand Up @@ -321,6 +336,8 @@ By default, publishing an app disables the preceding properties by setting them

:::moniker-end

-->

## Attach to an existing debugging session

To attach to a running Blazor app, create a `.vscode/launch.json` file with the following configuration. Replace the `{URL}` placeholder with the URL where the app is running:
Expand All @@ -343,17 +360,22 @@ The following launch configuration options are supported for the `blazorwasm` de

| Option | Description |
| --------- | ----------- |
| `request` | Use `launch` to launch and attach a debugging session to a Blazor WebAssembly app or `attach` to attach a debugging session to an already-running app. |
| `url` | The URL to open in the browser when debugging. |
| `browser` | The browser to launch for the debugging session. Set to `edge` or `chrome`. Defaults to `edge`. |
| `cwd` | The working directory to launch the app under. |
| `request` | Use `launch` to launch and attach a debugging session to a Blazor WebAssembly app or `attach` to attach a debugging session to an already-running app. |
| `timeout` | The number of milliseconds to wait for the debugging session to attach. Defaults to 30,000 milliseconds (30 seconds). |
| `trace` | Used to generate logs from the JS debugger. Set to `true` to generate logs. |
| `hosted` | Must be set to `true` if launching and debugging a hosted Blazor WebAssembly app. |
| `url` | The URL to open in the browser when debugging. |
| `webRoot` | Specifies the absolute path of the web server. Should be set if an app is served from a sub-route. |
| `timeout` | The number of milliseconds to wait for the debugging session to attach. Defaults to 30,000 milliseconds (30 seconds). |

<!-- UPDATE 8.0 Holding for BWA/8.0 updates

| `hosted` | Must be set to `true` if launching and debugging a hosted Blazor WebAssembly app. |
| `program` | A reference to the executable to run the server of the hosted app. Must be set if `hosted` is `true`. |
| `cwd` | The working directory to launch the app under. Must be set if `hosted` is `true`. |
| `env` | The environment variables to provide to the launched process. Only applicable if `hosted` is set to `true`. |

-->

---

## Debug in the browser
Expand Down Expand Up @@ -407,7 +429,7 @@ To debug a Blazor WebAssembly app in Firefox during development:
1. Close all Firefox instances and reopen Firefox with remote debugging enabled by running the following command in a command shell: `firefox --start-debugger-server 6000 -new-tab about:debugging`.
1. In the new Firefox instance, leave the `about:debugging` tab open and open the Blazor WebAssembly app in a new browser tab.
1. Type <kbd>SHIFT</kbd>+<kbd>ALT</kbd> to open the Firefox Web Developer tools and connect to the Firefox browser instance.
1. In the `Debugger` tab, open the app source file you wish to debug under the `file://` node and set a breakpoint. For example, set a breakpoint in the `IncrementCount` method of the `Counter` component (`Pages/Counter.razor`).
1. In the `Debugger` tab, open the app source file you wish to debug under the `file://` node and set a breakpoint. For example, set a breakpoint in the `IncrementCount` method of the `Counter` component (`Counter.razor`).
1. Navigate to the `Counter` component page (`/counter`) and select the counter button to hit the breakpoint.

:::moniker-end
Expand Down
2 changes: 1 addition & 1 deletion aspnetcore/blazor/file-uploads.md
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ In the preceding code, <xref:System.IO.Path.GetRandomFileName%2A> is called to g

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

*This section applies to client-side rendered Razor components in Blazor Web Apps and hosted Blazor WebAssembly apps.*
*This section applies to client-side rendered Razor components in Blazor Web Apps.*

:::moniker-end

Expand Down
22 changes: 19 additions & 3 deletions aspnetcore/blazor/forms-and-input-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -1875,17 +1875,19 @@ When validation messages are set in the component, they're added to the validato

## Server validation with a validator component

*This section is focused on hosted Blazor WebAssembly scenarios, but the approach for any type of app that uses server validation with web API adopts the same general approach.*

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

<!-- UPDATE 8.0 Will work this ASAP, but it might be post-RTM. -->

> [!NOTE]
> This section hasn't been updated to include [new .NET 8 antiforgery support features](#antiforgery-support) or guidance for Blazor Web Apps. Article updates are scheduled by [Add server validation with validator components for 8.0/BWA (dotnet/AspNetCore.Docs #30055)](https://github.com/dotnet/AspNetCore.Docs/issues/30055).
> For prior releases of .NET, this section was based on a hosted Blazor WebAssembly example, but hosted Blazor WebAssembly is no longer a supported project template in .NET 8. This section hasn't been updated to include new [.NET 8 antiforgery support features](#antiforgery-support) and guidance for Blazor Web Apps. Article updates for this section are scheduled by [Add server validation with validator components for 8.0/BWA (dotnet/AspNetCore.Docs #30055)](https://github.com/dotnet/AspNetCore.Docs/issues/30055). You can inspect the prior guidance by selecting an earlier version of this article.

:::moniker-end

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

*This section is focused on hosted Blazor WebAssembly scenarios, but the approach for any type of app that uses server validation with web API adopts the same general approach.*

Server validation is supported in addition to client-side validation:

* Process client-side validation in the form with the <xref:Microsoft.AspNetCore.Components.Forms.DataAnnotationsValidator> component.
Expand Down Expand Up @@ -2335,6 +2337,8 @@ moniker-end
> * [Azure Active Directory (AAD) B2C](xref:blazor/security/webassembly/hosted-with-azure-active-directory-b2c)
> * [Identity Server](xref:blazor/security/webassembly/hosted-with-identity-server)

:::moniker-end

## `InputText` based on the input event

Use the <xref:Microsoft.AspNetCore.Components.Forms.InputText> component to create a custom component that uses the `oninput` event ([`input`](https://developer.mozilla.org/docs/Web/API/HTMLElement/input_event)) instead of the `onchange` event ([`change`](https://developer.mozilla.org/docs/Web/API/HTMLElement/change_event)). Use of the `input` event triggers field validation on each keystroke.
Expand Down Expand Up @@ -3735,9 +3739,21 @@ For more information and guidance, see the following resources:

## Additional resources

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

* <xref:blazor/file-uploads>
* [Blazor samples GitHub repository (`dotnet/blazor-samples`)](https://github.com/dotnet/blazor-samples)
* [ASP.NET Core GitHub repository (`dotnet/aspnetcore`) forms test assets](https://github.com/dotnet/aspnetcore/tree/main/src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/Forms)

:::moniker-end

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

* <xref:blazor/file-uploads>
* <xref:blazor/security/webassembly/hosted-with-microsoft-entra-id>
* <xref:blazor/security/webassembly/hosted-with-azure-active-directory-b2c>
* <xref:blazor/security/webassembly/hosted-with-identity-server>
* [Blazor samples GitHub repository (`dotnet/blazor-samples`)](https://github.com/dotnet/blazor-samples)
* [ASP.NET Core GitHub repository (`dotnet/aspnetcore`) forms test assets](https://github.com/dotnet/aspnetcore/tree/main/src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/Forms)

:::moniker-end
Loading