Scaffolding Identity does not create Required Pages for Login and Register

bibash acharya 20 Reputation points
2025-04-11T03:28:30.7366667+00:00

I am trying to Scaffold Identity UI containing Login.cshtml and Register.cshtml for my ASP.NET Core application.

The code in my Program.cs file is:


using ObjectCrudApp.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using ObjectCrudApp.Areas.Identity.Data;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container
builder.Services.AddDbContext<AppDbContext>(options =>
    options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));

builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true).AddEntityFrameworkStores<ObjectCrudAppIdentityDbContext>();

// Configure Identity services
builder.Services.AddIdentity<IdentityUser, IdentityRole>(options =>
    options.SignIn.RequireConfirmedAccount = false) // Customize as per your needs
    .AddEntityFrameworkStores<AppDbContext>() // Use the same DbContext for both App and Identity
    .AddDefaultTokenProviders();

// Configure Application Cookie for Access Denied
builder.Services.ConfigureApplicationCookie(options =>
{
    options.AccessDeniedPath = "/Identity/Account/AccessDenied"; // Path to redirect when access is denied
});

// Add MVC services to the container
builder.Services.AddControllersWithViews();

var app = builder.Build();

// Configure the HTTP request pipeline
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    app.UseHsts(); // HTTP Strict Transport Security
}

app.UseHttpsRedirection();
app.UseRouting();

app.UseAuthentication(); // Make sure authentication comes before authorization
app.UseAuthorization();

// Map the controller routes
app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();


I ran the command:

dotnet aspnet-codegenerator identity --useDefaultUI --fo

but it creates only _ValidationScriptsPartial.cshtml and _ViewStart.cshtml under the Areas/Pages, but I want all files:

Login.cshtml, Register.cshtml, AccessDenied.cshtml, ForgotPassword.cshtml, ResetPassword.cshtml

Here is the screenshot of my project directory:

scaffolding

I am trying to Scaffold Identity UI containing Login and Register for my ASP.NET Core application. I want my command to generate Login.cshtml and Register.cshtml and after I run scaffolding command I dont get those pages.

Community Center Not monitored
{count} votes

Accepted answer
  1. SurferOnWww 4,631 Reputation points
    2025-04-11T04:33:47.5033333+00:00

    Please try the followings:

    (1) Create ASP.NET Core project with Authentication type: none.

    enter image description here

    (2) Install the NuGet package Microsoft.VisualStudio.Web.CodeGeneration.Design.

    enter image description here

    (3) Install the ASP.NET Core Identity by scaffolding operation of Visual Studio.

    enter image description here

    enter image description here

    (4) Check if source code of ASP.NET Core Identity is generated.

    enter image description here

    (5) Rebuild solution.

    (6) Add _LoginPartial to Views/Shared/_Layout.cshtml.

    enter image description here

    (7) Check if Register and Login buttons are shown.

    enter image description here

    (8) Add builder.Services.AddRazorPages(); and app.MapRazorPages(); to Program.cs.

    enter image description here

    (9) Perform Add-Migration and Update-Database to create database


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.