From 5758bad4b94c1cb2476c4aab1884d713908dd7e5 Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Wed, 25 Mar 2026 11:15:48 -0400 Subject: [PATCH 1/3] Update MAUI BH Web Identity article --- .../blazor/hybrid/security/maui-blazor-web-identity.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aspnetcore/blazor/hybrid/security/maui-blazor-web-identity.md b/aspnetcore/blazor/hybrid/security/maui-blazor-web-identity.md index e180afc522a0..f79dc2472ba8 100644 --- a/aspnetcore/blazor/hybrid/security/maui-blazor-web-identity.md +++ b/aspnetcore/blazor/hybrid/security/maui-blazor-web-identity.md @@ -5,7 +5,7 @@ description: Learn how to build a .NET MAUI Blazor Hybrid app with a Blazor Web monikerRange: '>= aspnetcore-9.0' ms.author: wpickett ms.custom: mvc -ms.date: 11/11/2025 +ms.date: 03/24/2026 uid: blazor/hybrid/security/maui-blazor-web-identity --- # .NET MAUI Blazor Hybrid and Web App with ASP.NET Core Identity @@ -37,7 +37,7 @@ For prerequisites and preliminary steps, see The sample app is a starter solution that contains a native, cross-platform MAUI Blazor Hybrid app, a Blazor Web App, and a Razor class library (RCL) that contains the shared UI (Razor components) used by the native and web apps. 1. Clone this repository or download a ZIP archive of the repository. For more information, see [How to download a sample](xref:fundamentals/index#how-to-download-a-sample). -1. Make sure you have [.NET 9 and the MAUI workload installed (.NET MAUI documentation)](/dotnet/maui/get-started/installation). +1. Make sure you have [the latest .NET installed with the MAUI workload](/dotnet/maui/get-started/installation). 1. Open the solution in Visual Studio (2022 or later) or VS Code with the .NET MAUI extension installed. 1. Set the `MauiBlazorWeb` MAUI project as the startup project. In Visual Studio, right-click the project and select **Set as Startup Project**. 1. Start the `MauiBlazorWeb.Web` project without debugging. In Visual Studio, right-click on the project and select **Debug** > **Start without Debugging**. @@ -45,14 +45,14 @@ The sample app is a starter solution that contains a native, cross-platform MAUI 1. Navigate to `https://localhost:7157/account/register` to register a user in the Blazor Web App. Immediately after the user is registered, use the **Click here to confirm your account** link in the UI to confirm the user's email address because a real email sender isn't registered for account confirmation. 1. Start (`F5`) the `MauiBlazorWeb` MAUI project. You can set the debug target to either **Windows** or an Android emulator. 1. Notice you can only see the `Home` and `Login` pages. -1. Log in with the user that you registered. +1. Log in with the user that you registered or an existing Windows account. 1. Notice you can now see the shared `Counter` and `Weather` pages. 1. Log out and notice you can only see the `Home` and `Login` pages again. 1. Navigate to `https://localhost:7157/` in a browser and the web app behaves the same. ## Shared UI -The shared UI is in the `MauiBlazorWeb.Shared` project. This project contains the Razor components that are shared between the MAUI and Blazor Web App projects (Home, Counter and Weather pages). The `Counter` component and `Weather` component are protected by [`[Authorize]` attributes](xref:Microsoft.AspNetCore.Authorization.AuthorizeAttribute), so users can't navigate to them unless they're logged into the app. +The shared UI is in the `MauiBlazorWeb.Shared` project. This project contains the Razor components that are shared between the MAUI and Blazor Web App projects (Home, Counter and Weather pages). The `Counter` and `Weather` components are protected by [`[Authorize]` attributes](xref:Microsoft.AspNetCore.Authorization.AuthorizeAttribute), so users can't navigate to them unless they're logged into the app. In the [Razor directives](xref:blazor/components/index#razor-syntax) at the tops of the `Counter` component (`MauiBlazorWeb.Shared/Pages/Counter.razor`) and `Weather` component (`MauiBlazorWeb.Shared/Pages/Weather.razor`) files: From c679592b0c9e7434b6a4882a8266dcff0d4da06d Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Thu, 2 Apr 2026 16:07:13 -0400 Subject: [PATCH 2/3] Update MAUI Blazor Web Identity topic for new samp --- .../security/maui-blazor-web-identity.md | 51 +------------------ 1 file changed, 2 insertions(+), 49 deletions(-) diff --git a/aspnetcore/blazor/hybrid/security/maui-blazor-web-identity.md b/aspnetcore/blazor/hybrid/security/maui-blazor-web-identity.md index f79dc2472ba8..46f0aaeb7b97 100644 --- a/aspnetcore/blazor/hybrid/security/maui-blazor-web-identity.md +++ b/aspnetcore/blazor/hybrid/security/maui-blazor-web-identity.md @@ -52,7 +52,7 @@ The sample app is a starter solution that contains a native, cross-platform MAUI ## Shared UI -The shared UI is in the `MauiBlazorWeb.Shared` project. This project contains the Razor components that are shared between the MAUI and Blazor Web App projects (Home, Counter and Weather pages). The `Counter` and `Weather` components are protected by [`[Authorize]` attributes](xref:Microsoft.AspNetCore.Authorization.AuthorizeAttribute), so users can't navigate to them unless they're logged into the app. +The shared UI is in the `MauiBlazorWeb.Shared` project. This project contains the Razor components that are shared between the MAUI and Blazor Web App projects (Home, Counter, and Weather pages). The `Counter` and `Weather` components are protected by [`[Authorize]` attributes](xref:Microsoft.AspNetCore.Authorization.AuthorizeAttribute), so users can't navigate to them unless they're logged into the app. In the [Razor directives](xref:blazor/components/index#razor-syntax) at the tops of the `Counter` component (`MauiBlazorWeb.Shared/Pages/Counter.razor`) and `Weather` component (`MauiBlazorWeb.Shared/Pages/Weather.razor`) files: @@ -147,54 +147,7 @@ private async Task LoginUser() ### MAUI Authentication State Provider (`MauiAuthenticationStateProvider`) -The `MauiAuthenticationStateProvider` class is responsible for managing the user's authentication state and providing the to the app. The `MauiAuthenticationStateProvider` class uses an to make requests to the server to authenticate the user. For more information, see . - -In `MauiBlazorWeb/Services/MauiAuthenticationStateProvider.cs`: - -```csharp - private async Task LoginWithProviderAsync(LoginRequest loginModel) - { - var authenticatedUser = _defaultUser; - LoginStatus = LoginStatus.None; - - try - { - // Call the Login endpoint and pass the email and password - var httpClient = HttpClientHelper.GetHttpClient(); - var loginData = new { loginModel.Email, loginModel.Password }; - using var response = await httpClient.PostAsJsonAsync(HttpClientHelper.LoginUrl, - loginData); - - LoginStatus = - response.IsSuccessStatusCode ? LoginStatus.Success : LoginStatus.Failed; - - if (LoginStatus == LoginStatus.Success) - { - // Save token to secure storage so the user doesn't have to login - // every time - var token = await response.Content.ReadAsStringAsync(); - _accessToken = await TokenStorage.SaveTokenToSecureStorageAsync(token, - loginModel.Email); - - authenticatedUser = CreateAuthenticatedUser(loginModel.Email); - LoginStatus = LoginStatus.Success; - } - else - { - LoginFailureMessage = "Invalid Email or Password. Please try again."; - LoginStatus = LoginStatus.Failed; - } - } - catch (Exception ex) - { - Debug.WriteLine($"Error logging in: {ex}"); - LoginFailureMessage = "Server error."; - LoginStatus = LoginStatus.Failed; - } - - return authenticatedUser; -} -``` +The `MauiAuthenticationStateProvider` class (`MauiBlazorWeb/Services/MauiAuthenticationStateProvider.cs`) is responsible for managing the user's authentication state and providing the to the app. The `MauiAuthenticationStateProvider` class uses an to make requests to the server to authenticate the user. For more information, see . The `MauiAuthenticationStateProvider` class uses the `HttpClientHelper` (`MauiBlazorWeb/Services/HttpClientHelper.cs`) to handle calling localhost via the emulators and simulators for testing. For more information on calling local services from emulators and simulators, see [Connect to local web services from Android emulators and iOS simulators (.NET MAUI documentation)](/dotnet/maui/data-cloud/local-web-services). From 24422ce934ce099e015fe33f8b8ff9dca7e0b685 Mon Sep 17 00:00:00 2001 From: guardrex <1622880+guardrex@users.noreply.github.com> Date: Thu, 2 Apr 2026 16:14:31 -0400 Subject: [PATCH 3/3] Updates --- aspnetcore/blazor/hybrid/security/maui-blazor-web-identity.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aspnetcore/blazor/hybrid/security/maui-blazor-web-identity.md b/aspnetcore/blazor/hybrid/security/maui-blazor-web-identity.md index 46f0aaeb7b97..694da21873a0 100644 --- a/aspnetcore/blazor/hybrid/security/maui-blazor-web-identity.md +++ b/aspnetcore/blazor/hybrid/security/maui-blazor-web-identity.md @@ -5,7 +5,7 @@ description: Learn how to build a .NET MAUI Blazor Hybrid app with a Blazor Web monikerRange: '>= aspnetcore-9.0' ms.author: wpickett ms.custom: mvc -ms.date: 03/24/2026 +ms.date: 04/02/2026 uid: blazor/hybrid/security/maui-blazor-web-identity --- # .NET MAUI Blazor Hybrid and Web App with ASP.NET Core Identity @@ -45,7 +45,7 @@ The sample app is a starter solution that contains a native, cross-platform MAUI 1. Navigate to `https://localhost:7157/account/register` to register a user in the Blazor Web App. Immediately after the user is registered, use the **Click here to confirm your account** link in the UI to confirm the user's email address because a real email sender isn't registered for account confirmation. 1. Start (`F5`) the `MauiBlazorWeb` MAUI project. You can set the debug target to either **Windows** or an Android emulator. 1. Notice you can only see the `Home` and `Login` pages. -1. Log in with the user that you registered or an existing Windows account. +1. Log in with the user that you registered. 1. Notice you can now see the shared `Counter` and `Weather` pages. 1. Log out and notice you can only see the `Home` and `Login` pages again. 1. Navigate to `https://localhost:7157/` in a browser and the web app behaves the same.