How to do it...

Let's dive into the code:

  1. First, create a new project by running the following scripts in Command Prompt / Terminal:
dotnet new web -n AspNetCoreIdentitySample 
dotnet restore 
  1. Open Startup.cs file, and change the ConfigureServices() method, as follows:
public void ConfigureServices(IServiceCollection services) 
{ 
    services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=AspNetCoreIdentitySample;Data Source=.")); 
 
    services.AddIdentity<ApplicationUser, IdentityRole>() 
            .AddEntityFrameworkStores<ApplicationDbContext>() 
            .AddDefaultTokenProviders(); 
 
    services.AddMvc(); 
} 
  1. We set up the connection string and point that to our local database ...

Get ASP.NET Core MVC 2.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.