chikor.net
chikor.net

Reputation: 387

ASP.NET IServiceCollection AddIdentity not found

I have a situation (database-first approach) where I want to change the password length of ASP.NET IdentityUser to let's say 4 characters. After much research, I found I can do it from the Startup class with:

public void ConfigureServices(IServiceCollection services)
{
    services.AddIdentity<ApplicationUser, IdentityRole>(options =>
    {
        options.Password.RequireDigit = false;
        options.Password.RequiredLength = 4;
    })
    .AddEntityFrameworkStores<ApplicationDbContext>()
    .AddDefaultTokenProviders();
}

I have downloaded the following packages, but still, AddIdentity cannot be found:

Upvotes: 6

Views: 9980

Answers (3)

David Liang
David Liang

Reputation: 21546

If you're doing it in Microsoft.NET.Sdk.Web (web project), bringing it the namespace Microsoft.AspNetCore.Identity would resolve AddIdentity<TUser, TRole>.

However, if you're writing an extension method from Microsoft.NET.Sdk (class project), no matter which NuGet packages you install, you won't find that extension method..., until you install Microsoft.AspNetCore.Identity.UI.

I think it's confusing. I used to be able to just install Microsoft.AspNetCore.Identity NuGet (now it's deprecated) because I don't use all the features from the UI package. I rather build my own views.

Upvotes: 2

Barcollin
Barcollin

Reputation: 107

You need to add this nugget package Microsoft.AspNetCore.Identity.UI this worked for me

Upvotes: 2

Camilo Terevinto
Camilo Terevinto

Reputation: 32072

AddIdentity and it's related extension methods are part of ASP.NET Core Identity, which resides on the NuGet package Microsoft.AspNetCore.Identity.

AddEntityFrameworkStores is part of EntityFrameworkCore for ASP.NET Core Identity package Microsoft.AspNetCore.Identity.EntityFrameworkCore

Upvotes: 16

Related Questions