Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
The debug log message for a successful logout in Blazor WebAssembly incorrectly states that a successful login has occurred.
Looks like maybe a bit of copypasta made its way into RemoteAuthenticatorViewCore.Log.cs - note name of the method the attribute decorates:
Expected Behavior
Upon successful logout in a Blazor WASM project with logging enabled, the log entry should refer to logout instead of login as it does currently.
Essentially, the first line in this snippet:
Should instead refer to logout, as shown here:
[LoggerMessage(10, LogLevel.Debug, "Logout completed successfully.", EventName = nameof(LogoutCompletedSuccessfully))]
public static partial void LogoutCompletedSuccessfully(ILogger logger);
Steps To Reproduce
-
Follow the steps for Visual Studio Code in the Microsoft Learn article Secure an ASP.NET Core Blazor WebAssembly standalone app with the Authentication library to create a Blazor WASM app by using the
dotnet
CLI and theIndividual Authentication
template. -
Add support for successfully logging the user out of your app.
-
Enable logging as described in the Learn article section, Logging in Blazor WebAssembly apps.
-
In Program.cs, set the log level to "trace":
builder.Logging.SetMinimumLevel(LogLevel.Trace);
-
Enable debugging in Visual Studio Code as described in Debug a standalone Blazor WebAssembly app.
-
Run with debugging in Visual Studio Code.
-
Sign in to your app with a valid user account.
-
Sign out of your app.
-
View the log output in the DEBUG CONSOLE pane in Visual Studio Code (you might need to select Debug Blazor WebAssembly in Browser by using the drop-down).
In the log output, you'll see output similar to the following showing the logout operation being logged as a login operation (the Login completed successfully.
line).
dbug: Microsoft.AspNetCore.Components.Routing.Router[2]
Navigating to component MyAwesomeBlazorWASMApp.Pages.Authentication in response to path 'authentication/logout' with base URI 'https://localhost:7007/'
dbug: Microsoft.AspNetCore.Components.RenderTree.Renderer[3]
Rendering component 4 of type Microsoft.AspNetCore.Components.Authorization.AuthorizeRouteView
# ...several render events omitted for brevity...
dbug: Microsoft.AspNetCore.Components.RenderTree.Renderer[3]
Rendering component 8 of type MyAwesomeBlazorWASMApp.Shared.MainLayout
dbug: Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticatorViewCore[10]
Login completed successfully.
dbug: Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticatorViewCore[12]
Raising LogoutCompleted event.
Exceptions (if any)
No response
.NET Version
8.0.100-alpha.1.22531.1
Anything else?
I'll submit a PR with the fix shortly. 🙂
Draft PR building now: #45847