Why can I use UserManager & SignInManager in a Blazor server app

David Thielen 2,796 Reputation points

I am successfully using UserManager & SignInManager in a Blazor server page:

private SignInManager<IdentityUser> SignInManager { get; set; } = default!;

private UserManager<IdentityUser> UserManager { get; set; } = default!;

I'm calling them to create a new user in the Identity DB and they work fine. And then yesterday I read this:

ASP.NET Core abstractions, such as SignInManager and UserManager, aren't supported in Razor components. For more information on using ASP.NET Core Identity with Blazor, see Scaffold ASP.NET Core Identity into a Blazor Server app.

So what's going on here? Is using these something that will fail on me at times? Or is this warning about something else?

thanks - dave

A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,499 questions
0 comments No comments
{count} votes

Accepted answer
  1. AgaveJoe 27,686 Reputation points

    The SinginManager has many methods that are dependent on an injected HTTP context. These methods may not function as expected in Blazor Server.

    Avoid IHttpContextAccessor/HttpContext in Razor components

    As far as I know, the UserManger does not have dependencies on the HTTP Context and should be okay.

    The source code is on GitHub.



    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 61,491 Reputation points

    A blazor server has an injected HttpContext, but there is no access to the response stream (as it’s completed before the blazor components are loaded. All blazor browser communication is over the signalr connection.

    the identity library is razor page library and assumes it can do redirects or set cookies using context. But the blazor HttpContext is basically read only.

    so the database routines will work, but not any that require a ui or a redirect.