Hi,
The core issue is a mismatch between what you want (Identity cookie auth) and the render mode you chose. Cookie-based ASP.NET Core Identity only works naturally when the component runs on the server (InteractiveServer or InteractiveAuto). You can’t make just HandleOnValidSubmit run on WebAssembly; render mode applies to the whole component. You also don’t need client-side execution to receive a Set-Cookie; the server issues it and the browser stores it automatically. So drop InteractiveWebAssembly for this page and let the server handle registration + sign-in.
To keep Identity, Cookie Auth and Use Server Interactivity:
Change the rendermode component to run all events (including submit) on the server so Identity’s cookie is recognized immediately.
@page "/auth/register"
@rendermode InteractiveServer
For submit handler, force a round trip so the new cookie is on the next request
if (res.IsSuccessStatusCode)
{
navigation.NavigateTo("/", forceLoad: true);
return;
}
In Program.cs, ensure the app can issue/read auth cookies during server-side events
// Identity & Cookie Auth
builder.Services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<AppDbContext>()
.AddDefaultTokenProviders(); // Tokens for reset/email if needed
builder.Services.AddAuthentication()
.AddCookie(IdentityConstants.ApplicationScheme); // HttpOnly auth cookie
// Razor Components with server interactivity
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
// Middleware pipeline
app.UseAuthentication();
app.UseAuthorization();
// Map the root components (server render mode only needed here)
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
Registration endpoint (create + sign in):
// Issues the auth cookie on success
app.MapPost("/auth/register", async (
RegisterModel model,
UserManager<ApplicationUser> userManager,
SignInManager<ApplicationUser> signInManager) =>
{
var user = new ApplicationUser
{
UserName = model.Email,
Email = model.Email,
FirstName = model.FirstName,
LastName = model.LastName
};
var result = await userManager.CreateAsync(user, model.Password);
if (!result.Succeeded)
{
var errors = result.Errors
.GroupBy(e => e.Code)
.ToDictionary(g => g.Key, g => g.Select(e => e.Description).ToArray());
return Results.ValidationProblem(errors); // Matches your ValidationMessageStore usage
}
await signInManager.SignInAsync(user, isPersistent: model.KeepLogin); // Writes Set-Cookie
return Results.Ok();
});
Hope this helps. Please reach out if you need any help.