2.5 KiB
2.5 KiB
Run the Identity scaffolder:
Visual Studio
- From Solution Explorer, right-click on the project > Add > New Scaffolded Item.
- From the left pane of the Add New Scaffolded Item dialog, select Identity. Select Identity in the center pane. Select the Add button.
- In the Add Identity dialog, select the options you want.
- If you have an existing, customized layout page for Identity (
_Layout.cshtml
), select your existing layout page to avoid overwriting your layout with incorrect markup by the scaffolder. For example, select either:Pages/Shared/_Layout.cshtml
for Razor Pages or Blazor Server projects with existing Razor Pages infrastructure.Views/Shared/_Layout.cshtml
for MVC projects or Blazor Server projects with existing MVC infrastructure.
- For the data context (DbContext class):
- Select your data context class. You must select at least one file to add your data context.
- To create a data context and possibly create a new user class for Identity, select the + button. Accept the default value or specify a class (for example,
Contoso.Data.ApplicationDbContext
for a company named "Contoso"). To create a new user class, select the + button for User class and specify the class (for example,ContosoUser
for a company named "Contoso").
- Select the Add button to run the scaffolder.
- If you have an existing, customized layout page for Identity (
.NET Core CLI
If you have not previously installed the ASP.NET Core scaffolder, install it now:
dotnet tool install -g dotnet-aspnet-codegenerator
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
Run the following command to list the Identity scaffolder options:
dotnet aspnet-codegenerator identity -h
In the project folder, run the Identity scaffolder with the options you want. For example, to setup identity with the default UI and the minimum number of files, run the following command:
dotnet aspnet-codegenerator identity --useDefaultUI