From 14473850b9a4a5fd790857afd527becd3fa59bb9 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Wed, 6 Nov 2024 08:19:29 -0500 Subject: [PATCH 01/11] Fix bad identifiter (#34036) --- aspnetcore/blazor/components/js-spa-frameworks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/blazor/components/js-spa-frameworks.md b/aspnetcore/blazor/components/js-spa-frameworks.md index 427284c9de9b..cf713d91a97e 100644 --- a/aspnetcore/blazor/components/js-spa-frameworks.md +++ b/aspnetcore/blazor/components/js-spa-frameworks.md @@ -126,7 +126,7 @@ window.showQuote = async () => { }); } -const btn = document.querySelector("showQuoteBtn"); +const btn = document.querySelector("#showQuoteBtn"); btn.addEventListener("click", showQuote); ``` From 1b4668e865ec4e0038a234b41853ef8d39dd9909 Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Wed, 6 Nov 2024 05:55:41 -0800 Subject: [PATCH 02/11] .NET 9 migration guidance edit suggestions for MapStaticAssets (#34032) --- aspnetcore/migration/80-90.md | 51 ++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/aspnetcore/migration/80-90.md b/aspnetcore/migration/80-90.md index d2f2fd7ce4ff..39cac8ed925d 100644 --- a/aspnetcore/migration/80-90.md +++ b/aspnetcore/migration/80-90.md @@ -72,38 +72,45 @@ In the project file, update each [`Microsoft.AspNetCore.*`](https://www.nuget.or ## Replace `UseStaticFiles` with `MapStaticAssets` -Blazor has different update instructions for implementing Map Static Assets routing endpoint conventions than ASP.NET Core Razor Pages and MVC. +Optimize the handling of static files in your web apps by replacing with in the app's `Program` file: + +```diff +- app.UseStaticFiles(); ++ app.MapStaticAssets(); +``` + +In MVC & Razor Pages apps you additionally need to chain a call to `.WithStaticAssets` after `MapRazorPages` or `MapControllerRoute` in `Program.cs`. For an example, see the . + +ASP.NET Core automatically fingerprints and precompresses your static files at build and publish time, and then surfaces the optimized files as endpoints using endpoint routing with appropriate caching headers. -### Blazor Web App implementation -* Replace with in the app's `Program` file: - ```diff - - app.UseStaticFiles(); - + app.MapStaticAssets(); - ``` +To resolve the fingerprinted file names from your app: -* Assets are delivered via the property, which resolves the fingerprinted URL for a given asset. Update explicit references to static assets in Razor component files (`.razor`) to use `@Assets["{ASSET PATH}"]`, where the `{ASSET PATH}` placeholder is the path to the asset. This should ***NOT*** be done for the Blazor framework scripts (`blazor.*.js`). In the following example, Bootstrap, the Blazor project template app stylesheet (`app.css`), and the [CSS isolation stylesheet](xref:blazor/components/css-isolation) (based on an app's namespace of `BlazorSample`) are linked in a root component, typically the `App` component (`Components/App.razor`): +* In Blazor apps, use the property. Update explicit references to static assets in Razor component files (`.razor`) to use `@Assets["{ASSET PATH}"]`, where the `{ASSET PATH}` placeholder is the path to the asset. Note that this should ***NOT*** be done for the Blazor framework scripts (`blazor.*.js`). In the following example, Bootstrap, the Blazor project template app stylesheet (`app.css`), and the [CSS isolation stylesheet](xref:blazor/components/css-isolation) (based on an app's namespace of `BlazorSample`) are linked in a root component, typically the `App` component (`Components/App.razor`): - ```razor - - - - ``` + ```razor + + + + ``` + +* In MVC & Razor Pages apps, the script and link tag helpers will automatically resolve the fingerprinted file names. -* Add the Import Map component () to the `` content of the app's root component, typically the `App` component (`App.razor`): +To resolve the fingerprinted file names when importing JavaScript modules, add a generated [import map](https://developer.mozilla.org/docs/Web/HTML/Element/script/type/importmap): - ```razor - - ``` +* In Blazor apps, add the () component to the `` content of the app's root component, typically in the `App` component (`App.razor`): -For more information, see . + ```razor + + ``` -### ASP.NET Core Razor Pages and MVC implementation +* In MVC & Razor pages apps, add `` to the head of the main layout file, which is updated by the Import Map Tag Helper. + +For more information, see the following resources: -* Replace with in `Program.cs`. -* Chain a call to `.WithStaticAssets` after `MapRazorPages` or `MapControllerRoute` in `Program.cs`. For an example, see the . -* Add `` to the head of the main layout file. +* +* ## Blazor From a72cd19f6b1afd6b2cc90e2f0043361477970fce Mon Sep 17 00:00:00 2001 From: Robert Haken Date: Wed, 6 Nov 2024 15:16:21 +0100 Subject: [PATCH 03/11] [Blazor] Security overview - SecureMethod correction (#34031) --- aspnetcore/blazor/security/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aspnetcore/blazor/security/index.md b/aspnetcore/blazor/security/index.md index c58646d9c36c..60642e0ebdc1 100644 --- a/aspnetcore/blazor/security/index.md +++ b/aspnetcore/blazor/security/index.md @@ -439,7 +439,7 @@ You can also supply different content for display if the user isn't authorized w

Hello, @context.User.Identity?.Name!

-

+

You're not authorized.

@@ -447,11 +447,11 @@ You can also supply different content for display if the user isn't authorized w
@code { - private void SecureMethod() { ... } + private void HandleClick() { ... } } ``` -A default event handler for an authorized element, such as the `SecureMethod` method for the `