I know there are already several topics about this but none of them provides a satisfying solution so I want to give it another "year 2024" try.
I have a Blazor Web App using rendermode="InteractiveServer"
Now I want to implement authentication using AspNet Core
In my underlying database there are the corresponding AspNet tables and a corresponding user with the username and password test
My Login Code:
var userName = "test";var password = "test";var user = await UserManager.FindByNameAsync(userName);if (user == null){ // User does not exist}else{ // User exists, so try login // THROWS InvalidOperationException var signInResult = await SignInManager.PasswordSignInAsync(user, password, false, false); if (signInResult.Succeeded) { // Sign in successful } else { // Sign in unsuccessful }}PasswordSignInAsync throws the following error
Error: System.InvalidOperationException: Headers are read-only, response has already started.What I found out so far is that SignInManager attempts to set an authorization cookie, but since Serverside blazor works over SignalR and no HttpContext is available the error ist thrown.
Is there any clean solution for that?