ASP.NET Identity
AddIdentity
AddIdentityCore
Authentication
Web Development

AddIdentity vs AddIdentityCore in ASP.NET Core

Codemia Knowledge Hub ·

`AddIdentity` sets up the full ASP.NET Core Identity stack, including user, role and sign-in services and cookie authentication. `AddIdentityCore` registers only the core pieces, such as user management, and leaves everything else (including cookie authentication) for you to configure. Choose `AddIdentity` for a ready-made setup and `AddIdentityCore` when you want a minimal, customized one.

ASP.NET Core Identity is a membership system that adds login functionality to an application: creating and managing user accounts, creating roles, and managing authentication tokens. It supports local accounts and external logins through services like Google or Facebook.

What AddIdentity registers

`AddIdentity` is part of the ASP.NET Core Identity package and covers the identity features you typically need out of the box:

  • User and role management services: `UserManager`, `RoleManager` and `SignInManager`.
  • Cookie authentication: Configures cookie-based authentication.
csharp
builder.Services.AddIdentity<IdentityUser, IdentityRole>()
    .AddEntityFrameworkStores<ApplicationDbContext>()
    .AddDefaultTokenProviders();

It does not add the default Identity UI by itself. That comes from `AddDefaultUI`, and `AddDefaultIdentity` is similar to calling `AddIdentity`, `AddDefaultUI` and `AddDefaultTokenProviders` together.

Trade-offs:

  • Comprehensive functionality: Includes what a robust identity management system needs.
  • Ease of use: Ready-to-use authentication mechanisms.
  • Less customizable: Limited room to trim features you do not need.

What AddIdentityCore registers

csharp
builder.Services.AddIdentityCore<IdentityUser>()
    .AddEntityFrameworkStores<ApplicationDbContext>();
  • Minimal configuration: Only core features like user management.
  • Extensibility: Better suited to scenarios where specific services need customization.
  • No cookie authentication by default: Unlike `AddIdentity`, it does not set up cookie authentication.
  • Highly configurable: You tailor the identity setup to your application's needs.
  • Lighter: Because it is minimal, it can perform better when only essential features are required.
  • More setup required: Especially for authentication mechanisms it does not provide out of the box.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design