Problem with identity scaffolding in ASP.NET

43 Views Asked by At

I am trying to implement identity auth to my project but it's not creating an applicationdb class like it used to. I am new to coding so I am sorry if it looks dumb

Zenter image description here

I was expecting to get the db class like it used to create before

1

There are 1 best solutions below

0
Md Farid Uddin Kiron On BEST ANSWER

I am trying to implement identity auth to my project but it's not creating an applicationdb class like it used to. I am new to coding so I am sorry if it looks dumb

You haven't specified, which version of .NET you are using. However, in latest version or in .NET 8 Microsoft has moved away from a single pre-defined ApplicationDbContext class. Instead, it encourages developers to define their own DbContext while adding the Identity scaffholding.

You can define your own ApplicationDbContext by yourself before adding Identity or at the same time while adding identity within your project.

So, while you would click for adding Identity within your project, it would give you the option for DbContext configuration.

You can do as following:

enter image description here

Or you can create manually as following:

public class ApplicationDbContext : IdentityDbContext<IdentityUser>
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)
    {
    }
}

Output:

After successfull creation, you should have following output:

enter image description here

Note: Make sure, that you have the necessary NuGet packages installed for Identity. In ASP.NET Core 8, you typically need Microsoft.AspNetCore.Identity.EntityFrameworkCore package. Please refer to this official document, if you want to study more.