I have an issue around using Areas and Scaffolding Identity in .net core 6. I have tried numerous ways to resolve the issue and the following are the attempts. I'll post code at the end.
- Created a new MVC project and included Identity from the start. Without using Areas the site works correctly. Once I implement areas by scaffolding areas into the site, and moving all of the relevant files when I run the site it returns a blank page. I can manually navigate to the identity pages and they still work.
- Created a new MVC project with no Identity, scaffolded Areas and the site works correctly. Then scaffolded Identity into the project and the home page stopped functioning. Can still navigate to the Identity pages which work correctly.
program.cs
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using ObferoTest.Data;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connectionString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "areas",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
);
});
app.MapRazorPages();
app.Run();
HomeController.cs
using Microsoft.AspNetCore.Mvc;
namespace ObferoTest.Areas.Landing.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
}
}
If there is anything else I need to post please let me know and I will do so.