From e80b09c04f5f007413cb6d0b25301c3eed60595c Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Mon, 12 May 2025 09:50:23 -0400 Subject: [PATCH 1/6] [Pre4] Final round of Blazor content/WN updates --- aspnetcore/blazor/components/quickgrid.md | 4 ++-- aspnetcore/blazor/fundamentals/static-files.md | 4 ++-- .../aspnetcore-10/includes/blazor.md | 18 ++++++++---------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/aspnetcore/blazor/components/quickgrid.md b/aspnetcore/blazor/components/quickgrid.md index 702a7274c8ce..2999185c53ab 100644 --- a/aspnetcore/blazor/components/quickgrid.md +++ b/aspnetcore/blazor/components/quickgrid.md @@ -228,7 +228,7 @@ In the following example: ### Close `QuickGrid` column options -Close the `QuickGrid` column options UI with the `CloseColumnOptionsAsync` method. +Close the `QuickGrid` column options UI with the `HideColumnOptionsAsync` method. The following example closes the column options UI as soon as the title filter is applied: @@ -237,7 +237,7 @@ The following example closes the column options UI as soon as the title filter i + @bind:after="@(() => movieGrid.HideColumnOptionsAsync())" /> diff --git a/aspnetcore/blazor/fundamentals/static-files.md b/aspnetcore/blazor/fundamentals/static-files.md index eeebf695fd70..f1d81cd5ff5f 100644 --- a/aspnetcore/blazor/fundamentals/static-files.md +++ b/aspnetcore/blazor/fundamentals/static-files.md @@ -254,11 +254,11 @@ The following configuration must be present in the `wwwwoot/index.html` file of ``` -In the project file (`.csproj`), the `` property is set to `true`: +In the project file (`.csproj`), the `` property is set to `true`: ```xml - true + true ``` diff --git a/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md b/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md index 76483d34b090..555623ece961 100644 --- a/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md +++ b/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md @@ -65,16 +65,16 @@ For more information, see . ### Close `QuickGrid` column options -You can now close the `QuickGrid` column options UI using the new `CloseColumnOptionsAsync` method. +You can now close the `QuickGrid` column options UI using the new `HideColumnOptionsAsync` method. -The following example uses the `CloseColumnOptionsAsync` method to close the column options UI as soon as the title filter is applied: +The following example uses the `HideColumnOptionsAsync` method to close the column options UI as soon as the title filter is applied: ```razor + @bind:after="@(() => movieGrid.HideColumnOptionsAsync())" /> @@ -96,7 +96,7 @@ In prior Blazor releases, response streaming for for an (`response.Content.ReadAsStreamAsync()`) returns a `BrowserHttpReadStream` and no longer a . `BrowserHttpReadStream` doesn't support synchronous operations, such as `Stream.Read(Span)`. If your code uses synchronous operations, you can opt-out of response streaming or copy the into a yourself. - From 52135083b17521b4bb4cb14f70f50d0cbaae6c90 Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Mon, 12 May 2025 16:22:46 -0400 Subject: [PATCH 2/6] Updates --- .../release-notes/aspnetcore-10/includes/blazor.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md b/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md index 555623ece961..fa02e68690eb 100644 --- a/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md +++ b/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md @@ -384,3 +384,17 @@ AppContext.SetSwitch( ``` --> + +## Signal a Not Found response using `NavigationManager` + +The `NavigationManager` class now includes a `NotFound` method to handle scenarios where a requested resource isn't found: + +* **Static server-side rendering (static SSR)**: Calling `NotFound` sets the HTTP status code to 404. +* **Streaming rendering**: Throws an exception if the response has already started. +* **Interactive rendering**: Signals the `Router` to render a Not Found page. + +You can use the `OnNotFound` event on `NavigationManager` to be notified when `NotFound` is invoked. + + From ca29661a61efa0bd56b816dbe82fca5938de74b6 Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Mon, 12 May 2025 18:47:38 -0400 Subject: [PATCH 3/6] Updates --- .../webassembly-browser-developer-tools-diagnostics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/blazor/performance/webassembly-browser-developer-tools-diagnostics.md b/aspnetcore/blazor/performance/webassembly-browser-developer-tools-diagnostics.md index 8f839e396705..14e27cb16f41 100644 --- a/aspnetcore/blazor/performance/webassembly-browser-developer-tools-diagnostics.md +++ b/aspnetcore/blazor/performance/webassembly-browser-developer-tools-diagnostics.md @@ -43,7 +43,7 @@ Property | Default | Set value to… | Description `` | `true` | `false` | Controls stripping the native executable. `` | `true` | `true` | Controls building with native debug symbols. -Enabling profilers has negative size and performance impact, so don't publish an app for production with profilers enabled. In the following example, a condition is set on a property group section that only enables profiling when the app is built with `/p:BlazorSampleProfilingEnabled=true` (.NET CLI) or `true` in a Visual Studio publish profile, where "`BlazorSampleProfilingEnabled`" is a custom symbol name that you choose and doesn't conflict with other symbol names. +Enabling profilers has negative size and performance impacts, so don't publish an app for production with profilers enabled. In the following example, a condition is set on a property group section that only enables profiling when the app is built with `/p:BlazorSampleProfilingEnabled=true` (.NET CLI) or `true` in a Visual Studio publish profile, where "`BlazorSampleProfilingEnabled`" is a custom symbol name that you choose and doesn't conflict with other symbol names. In the app's project file (`.csproj`): From 440af07732c0af0ad71793f95921a46e31d87980 Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Mon, 12 May 2025 19:31:57 -0400 Subject: [PATCH 4/6] Updates --- aspnetcore/release-notes/aspnetcore-10/includes/blazor.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md b/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md index fa02e68690eb..5fcb045794ff 100644 --- a/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md +++ b/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md @@ -385,7 +385,7 @@ AppContext.SetSwitch( --> -## Signal a Not Found response using `NavigationManager` +## Signal Not Found responses using `NavigationManager` The `NavigationManager` class now includes a `NotFound` method to handle scenarios where a requested resource isn't found: From 0f7024a56cb0e09a862e3464df27e66f8a314853 Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Tue, 13 May 2025 07:34:08 -0400 Subject: [PATCH 5/6] Updates --- aspnetcore/blazor/fundamentals/routing.md | 127 +++++++++++++++++- .../aspnetcore-10/includes/blazor.md | 14 +- 2 files changed, 133 insertions(+), 8 deletions(-) diff --git a/aspnetcore/blazor/fundamentals/routing.md b/aspnetcore/blazor/fundamentals/routing.md index 5539d4a2baba..f417177b7fb2 100644 --- a/aspnetcore/blazor/fundamentals/routing.md +++ b/aspnetcore/blazor/fundamentals/routing.md @@ -571,7 +571,25 @@ Slashes and segments of the captured path are decoded. For a route template of ` Use to manage URIs and navigation in C# code. provides the event and methods shown in the following table. -:::moniker range=">= aspnetcore-8.0" +:::moniker range=">= aspnetcore-10.0" + + + +Member | Description +--- | --- + | Gets the current absolute URI. + | Gets the base URI (with a trailing slash) that can be prepended to relative URI paths to produce an absolute URI. Typically, corresponds to the `href` attribute on the document's `` element ([location of `` content](xref:blazor/project-structure#location-of-head-and-body-content)). + | Navigates to the specified URI. If `forceLoad` is `false`:
  • And enhanced navigation is available at the current URL, Blazor's enhanced navigation is activated.
  • Otherwise, Blazor performs a full-page reload for the requested URL.
If `forceLoad` is `true`:
  • Client-side routing is bypassed.
  • The browser is forced to load the new page from the server, whether or not the URI is normally handled by the client-side interactive router.

For more information, see the [Enhanced navigation and form handling](#enhanced-navigation-and-form-handling) section.

If `replace` is `true`, the current URI in the browser history is replaced instead of pushing a new URI onto the history stack.

+ | An event that fires when the navigation location has changed. For more information, see the [Location changes](#location-changes) section. +`NotFound` | Called to handle scenarios where a requested resource isn't found. For more information, see the [Not Found responses](#not-found-responses) section. + | Converts a relative URI into an absolute URI. + | Based on the app's base URI, converts an absolute URI into a URI relative to the base URI prefix. For an example, see the [Produce a URI relative to the base URI prefix](#produce-a-uri-relative-to-the-base-uri-prefix) section. +[`RegisterLocationChangingHandler`](#handleprevent-location-changes) | Registers a handler to process incoming navigation events. Calling always invokes the handler. + | Returns a URI constructed by updating with a single parameter added, updated, or removed. For more information, see the [Query strings](#query-strings) section. + +:::moniker-end + +:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0" Member | Description --- | --- @@ -684,6 +702,113 @@ The following component: For more information on component disposal, see . +:::moniker range=">= aspnetcore-10.0" + +## Not Found responses + + + +*In ASP.NET Core 10.0 Preview 4, Not Found responses are only available for static SSR and global interactive rendering. Per-page/component rendering support is planned for Preview 5 in June, 2025.* + + provides a `NotFound` method to handle scenarios where a requested resource isn't found during static server-side rendering (static SSR) or global interactive rendering: + +* **Static SSR**: Calling `NotFound` sets the HTTP status code to 404. +* **Streaming rendering**: Throws an exception if the response has already started. +* **Interactive rendering**: Signals the Blazor router ([`Router` component](xref:blazor/fundamentals/routing#route-templates)) to render Not Found content. + +When a component is rendered statically (static SSR) and `NavigationManager.NotFound` is called, the 404 status code is set on the response: + +```razor +@page "/render-not-found-ssr" +@inject NavigationManager Navigation + +@code { + protected override void OnInitialized() + { + Navigation.NotFound(); + } +} +``` + +Two approaches for providing Not Found content for global interactive rendering: + +* Use a Not Found page (Razor component). +* Specify Not Found content in the [`Router` component's](xref:blazor/fundamentals/routing#route-templates) property (`...` markup or by setting the `NotFound` parameter to a render fragment in C# code). + +The following example uses a Not Found page (`NotFoundPage` component) to render Not Found content. + +`NotFoundPage.razor`: + +```razor +

Not Found

+ +

Sorry! Nothing to show.

+``` + +Specify the `NotFoundPage` component to the `Router` component in `Routes.razor`. You might need to specify the component's namespace with an [`@using`](xref:mvc/views/razor#using) directive either at the top of the `Routes.razor` file or in an [`_Imports.razor` file](xref:blazor/components/index#component-name-class-name-and-namespace). + +```razor + + + ... + + + + + +``` + +When a component is rendered with a global interactive render mode, calling `NotFound` signals the Blazor router to render Not Found content, which is the `NotFoundPage` component: + +```razor +@page "/render-not-found-interactive" +@inject NavigationManager Navigation + +@if (RendererInfo.IsInteractive) +{ + +} + +@code { + private void TriggerNotFound() + { + Navigation.NotFound(); + } +} +``` + +You can use the `OnNotFound` event for notifications when `NotFound` is invoked. The following example uses a render fragment () to render the Not Found content. + +`Routes.razor`: + +```razor +@inject NavigationManager Navigation +@inject ILogger Logger + + + + + + + + +@code { + private RenderFragment renderFragment = + @

Not Found

Sorry! Nothing to show.

; + + protected override void OnInitialized() => Navigation.OnNotFound += OnNotFound; + + private void OnNotFound(object? sender, EventArgs args) + { + Logger.LogError("Something wasn't found!"); + } + + public void Dispose() => Navigation.OnNotFound -= OnNotFound; +} +``` + +:::moniker-end + :::moniker range=">= aspnetcore-8.0" ## Enhanced navigation and form handling diff --git a/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md b/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md index 5fcb045794ff..1cab3b67b83d 100644 --- a/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md +++ b/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md @@ -385,16 +385,16 @@ AppContext.SetSwitch( --> -## Signal Not Found responses using `NavigationManager` +## Not Found responses using `NavigationManager` for static SSR and global interactive rendering -The `NavigationManager` class now includes a `NotFound` method to handle scenarios where a requested resource isn't found: +The now includes a `NotFound` method to handle scenarios where a requested resource isn't found during static server-side rendering (static SSR) or global interactive rendering: * **Static server-side rendering (static SSR)**: Calling `NotFound` sets the HTTP status code to 404. * **Streaming rendering**: Throws an exception if the response has already started. -* **Interactive rendering**: Signals the `Router` to render a Not Found page. +* **Interactive rendering**: Signals the Blazor router ([`Router` component](xref:blazor/fundamentals/routing#route-templates)) to render Not Found content. -You can use the `OnNotFound` event on `NavigationManager` to be notified when `NotFound` is invoked. +Per-page/component rendering support is planned for Preview 5 in June, 2025. - +You can use the `NavigationManager.OnNotFound` event for notifications when `NotFound` is invoked. + +For more information and examples, see . From 23b6a76ae5f3618e6f44afbaf251838a76b0fd46 Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Tue, 13 May 2025 10:02:08 -0400 Subject: [PATCH 6/6] Updates --- aspnetcore/release-notes/aspnetcore-10/includes/blazor.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md b/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md index 1cab3b67b83d..3c40167daa12 100644 --- a/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md +++ b/aspnetcore/release-notes/aspnetcore-10/includes/blazor.md @@ -96,7 +96,7 @@ In prior Blazor releases, response streaming for for an (`response.Content.ReadAsStreamAsync()`) returns a `BrowserHttpReadStream` and no longer a . `BrowserHttpReadStream` doesn't support synchronous operations, such as `Stream.Read(Span)`. If your code uses synchronous operations, you can opt-out of response streaming or copy the into a yourself. - -## Not Found responses using `NavigationManager` for static SSR and global interactive rendering +### Not Found responses using `NavigationManager` for static SSR and global interactive rendering The now includes a `NotFound` method to handle scenarios where a requested resource isn't found during static server-side rendering (static SSR) or global interactive rendering: