diff --git a/aspnetcore/blazor/fundamentals/handle-errors.md b/aspnetcore/blazor/fundamentals/handle-errors.md index 768e82ed11bc..a14643a7af90 100644 --- a/aspnetcore/blazor/fundamentals/handle-errors.md +++ b/aspnetcore/blazor/fundamentals/handle-errors.md @@ -964,7 +964,7 @@ Infinite loops during rendering: * Causes the rendering process to continue forever. * Is equivalent to creating an unterminated loop. -In these scenarios, the Blazor fails and usually attempts to: +In these scenarios, Blazor fails and usually attempts to: * Consume as much CPU time as permitted by the operating system, indefinitely. * Consume an unlimited amount of memory. Consuming unlimited memory is equivalent to the scenario where an unterminated loop adds entries to a collection on every iteration. @@ -989,7 +989,18 @@ Consider manual render tree builder logic on the same level of complexity and wi ## Additional resources -:::moniker range=">= aspnetcore-8.0" +:::moniker range=">= aspnetcore-10.0" + +* [Handle caught exceptions outside of a Razor component's lifecycle](xref:blazor/components/sync-context#handle-caught-exceptions-outside-of-a-razor-components-lifecycle) +* [Not Found responses](xref:blazor/fundamentals/navigation#not-found-responses) +* +* † +* +* [Blazor samples GitHub repository (`dotnet/blazor-samples`)](https://github.com/dotnet/blazor-samples) ([how to download](xref:blazor/fundamentals/index#sample-apps)) + +:::moniker-end + +:::moniker range=">= aspnetcore-8.0 < aspnetcore-10.0" * [Handle caught exceptions outside of a Razor component's lifecycle](xref:blazor/components/sync-context#handle-caught-exceptions-outside-of-a-razor-components-lifecycle) * diff --git a/aspnetcore/blazor/security/includes/redirecttologin-component.md b/aspnetcore/blazor/security/includes/redirecttologin-component.md index a89e36e7ba4d..6c09b834ffbd 100644 --- a/aspnetcore/blazor/security/includes/redirecttologin-component.md +++ b/aspnetcore/blazor/security/includes/redirecttologin-component.md @@ -1,35 +1,8 @@ The `RedirectToLogin` component (`RedirectToLogin.razor`): * Manages redirecting unauthorized users to the login page. -* The current URL that the user is attempting to access is maintained by so that they can be returned to that page if authentication is successful using: +* The current URL that the user is attempting to access is maintained so that they can be returned to that page if authentication is successful using: * [Navigation history state](xref:blazor/fundamentals/navigation#navigation-history-state) in ASP.NET Core in .NET 7 or later. * A query string in ASP.NET Core in .NET 6 or earlier. Inspect the `RedirectToLogin` component in [reference source](https://github.com/dotnet/aspnetcore/tree/main/src/ProjectTemplates/Web.ProjectTemplates/content/ComponentsWebAssembly-CSharp). The location of the component changed over time, so use GitHub search tools to locate the component. - -The login path can be customized by the app (, [framework defaults (`dotnet/aspnetcore` reference source)](https://github.com/dotnet/aspnetcore/blob/main/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationDefaults.cs)). The project template's `RedirectToLogin` component uses the default login path of `authentication/login`. - -[!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)] - -If an app [customizes the login path](xref:blazor/security/webassembly/additional-scenarios#customize-app-routes), take either of the following approaches: - -* Match the path in the hard-coded string in the `RedirectToLogin` component. -* Inject to obtain the configured value. For example, take this approach when you customize the path with . - Add the following directives at the top of the `RedirectToLogin` component: - - ```razor - @using Microsoft.Extensions.Options - @inject IOptionsSnapshot> RemoteOptions - ``` - - Modify the component's redirect in the `OnInitialized` method: - - ```diff - - Navigation.NavigateToLogin("authentication/login"); - + Navigation.NavigateToLogin(RemoteOptions.Get(Options.DefaultName) - + .AuthenticationPaths.LogInPath); - ``` - - > [!NOTE] - > If other paths differ from the project template's paths or [framework's default paths](https://github.com/dotnet/aspnetcore/blob/main/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationDefaults.cs), they should managed in the same fashion. - diff --git a/aspnetcore/blazor/security/includes/remote-authentication-paths.md b/aspnetcore/blazor/security/includes/remote-authentication-paths.md new file mode 100644 index 000000000000..c807f826da2a --- /dev/null +++ b/aspnetcore/blazor/security/includes/remote-authentication-paths.md @@ -0,0 +1,27 @@ +Remote authentication paths are customized using on the property in the app's `Program` file. For the framework's default path values, see the [`dotnet/aspnetcore` reference source](https://github.com/dotnet/aspnetcore/blob/main/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationDefaults.cs). + +[!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)] + +If an app [customizes a remote authentication path](xref:blazor/security/webassembly/additional-scenarios#customize-app-routes), take either of the following approaches: + +* Match the path in hard-coded strings around the app. + +* Inject to obtain the configured value around the app. The following example demonstrates the approach for the [`RedirectToLogin` component](#redirecttologin-component). + + Add the following Razor directives to the top of the component's Razor file: + + ```razor + @using Microsoft.Extensions.Options + @inject IOptionsSnapshot> RemoteOptions + ``` + + Modify the component's redirect in the `OnInitialized` method: + + ```diff + - Navigation.NavigateToLogin("authentication/login"); + + Navigation.NavigateToLogin(RemoteOptions.Get(Options.DefaultName) + + .AuthenticationPaths.LogInPath); + ``` + + > [!NOTE] + > If other paths differ from the project template's paths or [framework's default paths](https://github.com/dotnet/aspnetcore/blob/main/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationDefaults.cs), manage them in the same fashion. diff --git a/aspnetcore/blazor/security/webassembly/hosted-with-azure-active-directory-b2c.md b/aspnetcore/blazor/security/webassembly/hosted-with-azure-active-directory-b2c.md index 43092547e8e2..ed6f6beb5aae 100644 --- a/aspnetcore/blazor/security/webassembly/hosted-with-azure-active-directory-b2c.md +++ b/aspnetcore/blazor/security/webassembly/hosted-with-azure-active-directory-b2c.md @@ -161,6 +161,12 @@ To configure the app to receive the value from the `name` claim type: }); ``` +## Remote authentication paths + +*This section pertains to the solution's **:::no-loc text="Client":::** app.* + +[!INCLUDE[](~/blazor/security/includes/remote-authentication-paths.md)] + ## Parts of the solution This section describes the parts of a solution generated from the Blazor WebAssembly project template and describes how the solution's **:::no-loc text="Client":::** and **:::no-loc text="Server":::** projects are configured for reference. There's no specific guidance to follow in this section for a basic working application if you created the app using the guidance in the [Walkthrough](#walkthrough) section. The guidance in this section is helpful for updating an app to authenticate and authorize users. However, an alternative approach to updating an app is to create a new app from the guidance in the [Walkthrough](#walkthrough) section and moving the app's components, classes, and resources to the new app. diff --git a/aspnetcore/blazor/security/webassembly/hosted-with-identity-server.md b/aspnetcore/blazor/security/webassembly/hosted-with-identity-server.md index 367051f04c5b..54c97ffed18f 100644 --- a/aspnetcore/blazor/security/webassembly/hosted-with-identity-server.md +++ b/aspnetcore/blazor/security/webassembly/hosted-with-identity-server.md @@ -77,6 +77,12 @@ For more information, see the [`dotnet new`](/dotnet/core/tools/dotnet-new) comm [!INCLUDE[](~/blazor/security/includes/run-the-app.md)] +## Remote authentication paths + +*This section pertains to the solution's **:::no-loc text="Client":::** app.* + +[!INCLUDE[](~/blazor/security/includes/remote-authentication-paths.md)] + ## Parts of the solution This section describes the parts of a solution generated from the Blazor WebAssembly project template and describes how the solution's **:::no-loc text="Client":::** and **:::no-loc text="Server":::** projects are configured for reference. There's no specific guidance to follow in this section for a basic working application if you created the app using the guidance in the [Walkthrough](#walkthrough) section. The guidance in this section is helpful for updating an app to authenticate and authorize users. However, an alternative approach to updating an app is to create a new app from the guidance in the [Walkthrough](#walkthrough) section and moving the app's components, classes, and resources to the new app. diff --git a/aspnetcore/blazor/security/webassembly/hosted-with-microsoft-entra-id.md b/aspnetcore/blazor/security/webassembly/hosted-with-microsoft-entra-id.md index 0ab65e6596e5..5a4100f19e1e 100644 --- a/aspnetcore/blazor/security/webassembly/hosted-with-microsoft-entra-id.md +++ b/aspnetcore/blazor/security/webassembly/hosted-with-microsoft-entra-id.md @@ -165,6 +165,12 @@ To configure the app to receive the value from the `name` claim type: }); ``` +## Remote authentication paths + +*This section pertains to the solution's **:::no-loc text="Client":::** app.* + +[!INCLUDE[](~/blazor/security/includes/remote-authentication-paths.md)] + ## Parts of the solution This section describes the parts of a solution generated from the Blazor WebAssembly project template and describes how the solution's **:::no-loc text="Client":::** and **:::no-loc text="Server":::** projects are configured for reference. There's no specific guidance to follow in this section for a basic working application if you created the app using the guidance in the [Walkthrough](#walkthrough) section. The guidance in this section is helpful for updating an app to authenticate and authorize users. However, an alternative approach to updating an app is to create a new app from the guidance in the [Walkthrough](#walkthrough) section and moving the app's components, classes, and resources to the new app. diff --git a/aspnetcore/blazor/security/webassembly/standalone-with-authentication-library.md b/aspnetcore/blazor/security/webassembly/standalone-with-authentication-library.md index bbdac35bf153..b2292543b09b 100644 --- a/aspnetcore/blazor/security/webassembly/standalone-with-authentication-library.md +++ b/aspnetcore/blazor/security/webassembly/standalone-with-authentication-library.md @@ -123,6 +123,10 @@ Use one of the following approaches to run the app: * Press F5. * .NET CLI command shell: Execute the `dotnet watch` (or `dotnet run`) command from the app's folder. +## Remote authentication paths + +[!INCLUDE[](~/blazor/security/includes/remote-authentication-paths.md)] + ## Parts of the app This section describes the parts of an app generated from the Blazor WebAssembly project template and how the app is configured. There's no specific guidance to follow in this section for a basic working application if you created the app using the guidance in the [Walkthrough](#walkthrough) section. The guidance in this section is helpful for updating an app to authenticate and authorize users. However, an alternative approach to updating an app is to create a new app from the guidance in the [Walkthrough](#walkthrough) section and moving the app's components, classes, and resources to the new app. diff --git a/aspnetcore/blazor/security/webassembly/standalone-with-azure-active-directory-b2c.md b/aspnetcore/blazor/security/webassembly/standalone-with-azure-active-directory-b2c.md index c60528c85d08..aed443b82be2 100644 --- a/aspnetcore/blazor/security/webassembly/standalone-with-azure-active-directory-b2c.md +++ b/aspnetcore/blazor/security/webassembly/standalone-with-azure-active-directory-b2c.md @@ -105,6 +105,10 @@ Use one of the following approaches to run the app: * Press F5. * .NET CLI command shell: Execute the `dotnet watch` (or `dotnet run`) command from the app's folder. +## Remote authentication paths + +[!INCLUDE[](~/blazor/security/includes/remote-authentication-paths.md)] + ## Parts of the app This section describes the parts of an app generated from the Blazor WebAssembly project template and how the app is configured. There's no specific guidance to follow in this section for a basic working application if you created the app using the guidance in the [Walkthrough](#walkthrough) section. The guidance in this section is helpful for updating an app to authenticate and authorize users. However, an alternative approach to updating an app is to create a new app from the guidance in the [Walkthrough](#walkthrough) section and moving the app's components, classes, and resources to the new app. diff --git a/aspnetcore/blazor/security/webassembly/standalone-with-microsoft-accounts.md b/aspnetcore/blazor/security/webassembly/standalone-with-microsoft-accounts.md index 1788ba510c5b..7cc502481ad8 100644 --- a/aspnetcore/blazor/security/webassembly/standalone-with-microsoft-accounts.md +++ b/aspnetcore/blazor/security/webassembly/standalone-with-microsoft-accounts.md @@ -79,6 +79,10 @@ Use one of the following approaches to run the app: * Press F5. * .NET CLI command shell: Execute the `dotnet watch` (or `dotnet run`) command from the app's folder. +## Remote authentication paths + +[!INCLUDE[](~/blazor/security/includes/remote-authentication-paths.md)] + ## Parts of the app This section describes the parts of an app generated from the Blazor WebAssembly project template and how the app is configured. There's no specific guidance to follow in this section for a basic working application if you created the app using the guidance in the [Walkthrough](#walkthrough) section. The guidance in this section is helpful for updating an app to authenticate and authorize users. However, an alternative approach to updating an app is to create a new app from the guidance in the [Walkthrough](#walkthrough) section and moving the app's components, classes, and resources to the new app. @@ -199,6 +203,7 @@ The F5. * .NET CLI command shell: Execute the `dotnet watch` (or `dotnet run`) command from the app's folder. +## Remote authentication paths + +[!INCLUDE[](~/blazor/security/includes/remote-authentication-paths.md)] + ## Parts of the app This section describes the parts of an app generated from the Blazor WebAssembly project template and how the app is configured. There's no specific guidance to follow in this section for a basic working application if you created the app using the guidance in the [Walkthrough](#walkthrough) section. The guidance in this section is helpful for updating an app to authenticate and authorize users. However, an alternative approach to updating an app is to create a new app from the guidance in the [Walkthrough](#walkthrough) section and moving the app's components, classes, and resources to the new app.