With Visual Studio I have created a Blazor Web App .net 8. I used the wizard to generate the template with Authentication Type = Individual Account and render mode = Auto.
Everything is OK and authentication works OK with all the generated pages from the template (Login, register etc…) BUT there is NO LOGOUT razor page scafolded by the template.
Of course tried to scaffold it but it crashed. I tried a lot of thing to create it manually and asking chatgpt but with no success.
Is there someone who has a clue how to add a logout page with the new template of web App??
The closest I came ,gives Not found when I logout, or when executing the page below it does not clear my authentication and return to the home page still authenticated
@page "/Account/Logout"
@using Microsoft.AspNetCore.Authentication
@using Microsoft.AspNetCore.Identity
@inject IHttpContextAccessor HttpContextAccessor
@inject NavigationManager Navigation
@code {
[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;
private readonly HttpClient _httpClient;
protected override async Task OnInitializedAsync()
{
//await HttpContextAccessor.HttpContext.SignOutAsync();
await HttpContext.SignOutAsync();
Navigation.NavigateTo("/", true);
}
}
1
This might help: https://github.com/BlazorPuzzle/puzzle-36
It happened to us if we started with an app without auth and then added the auth files afterwards. Check out the solution folder.
Carl
Carl Franklin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1