ASP.NET Core Interview Question #140

What are UserManager and SignInManager?

Authentication, Authorization & Security Mid-Level Intermediate

Quick Interview Answer

UserManager<TUser> provides user-management operations such as creating users, validating/changing passwords, managing roles and claims, generating tokens, and confirming accounts.

Detailed Explanation

UserManager<TUser> provides user-management operations such as creating users, validating/changing passwords, managing roles and claims, generating tokens, and confirming accounts.

SignInManager<TUser> handles authentication-oriented workflows such as password sign-in, sign-out, external login, and two-factor sign-in. Controllers or Razor Pages should use these services instead of implementing password verification or authentication-cookie creation manually.

Code Example

public class AccountController : Controller
{
    private readonly UserManager<ApplicationUser> _userManager;
    private readonly SignInManager<ApplicationUser> _signInManager;

    public AccountController(
        UserManager<ApplicationUser> userManager,
        SignInManager<ApplicationUser> signInManager)
    {
        _userManager = userManager;
        _signInManager = signInManager;
    }
}