DEV Community

Mahmoud Mahmoud
Mahmoud Mahmoud

Posted on

How to add Identity UI to dotnet project

If you have not previously installed the ASP.NET Core scaffolder, install it now:

dotnet tool install -g dotnet-aspnet-codegenerator
Enter fullscreen mode Exit fullscreen mode

Add required NuGet package references to the project file (.csproj
). Run the following commands in the project directory:

dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet add package Microsoft.AspNetCore.Identity.EntityFrameworkCore
dotnet add package Microsoft.AspNetCore.Identity.UI
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.EntityFrameworkCore.Tools
Enter fullscreen mode Exit fullscreen mode

If you get a scaffolding error, verify the Target Framework Moniker (TFM) matches the NuGet package version in the project file. For example, the following project file contains version 3.1 for .NET Core and the listed NuGet packages:

In the project folder, run the Identity scaffolder with the options you want. For example, to set up Identity with the default UI and the minimum number of files, run the following command. Use the correct fully qualified name for your DB context:

dotnet aspnet-codegenerator identity -dc MyApplication.Data.ApplicationDbContext --files "Account.Register;Account.Login"
Enter fullscreen mode Exit fullscreen mode

If you run the Identity scaffolder without specifying the --files
 flag or the --useDefaultUI
 flag, all the available Identity UI pages will be created in your project.

Main article
https://learn.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-6.0&tabs=netcore-cli

Top comments (0)