ASP.NET Core Identity AddDefaultIdentity vs AddIdentity
source link: https://www.stevefenton.co.uk/2021/11/asp-net-core-identity-adddefaultidentity-vs-addidentity/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
ASP.NET Core Identity AddDefaultIdentity vs AddIdentity
The short version on the difference between AddDefaultIdentity
and AddIdentity
is the default part adds in all the built-in controllers and views for logging in, recovering accounts, and password resets but doesn’t add roles. You can, though, add roles to AddDefaultIdentity
to get all the things.
AddDefaultIdentity
This examples shows how to add the default version with AddDefaultIdentity
but also adds roles on using AddRoles<IdentityRole>
. This achieves “ticks in all the boxes” on the matrix shown above.
services .AddDefaultIdentity<IdentityUser>(options => { // options are set here }) .AddRoles<IdentityRole>() .AddEntityFrameworkStores<ApplicationDbContext>();
With this code you get the tables, the roles, and the built in pages.
AddIdentity
This example shows the AddIdentity
version. You get the tables and roles for free, but you need to implement your own pages (which may be desirable, for example if you want full control over the experience for logins and registrations).
services .AddIdentity<IdentityUser>(options => { // options are set here }) .AddEntityFrameworkStores<ApplicationDbContext>();
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK