添加身份支架

问题描述 投票:0回答:3

我在尝试添加 Identity Scaffold 时遇到问题。

以下是添加身份支架的照片:

Identity Scaffold 的所有页面均已加载到 Account 中。

如果我删除 Identity Scaffold 的页面,Web 服务将正常工作。

以下是 404 Chrome 和 Visual Studio 中的照片:

这是Program.cs的代码

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(
builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddDefaultIdentity<IdentityUser>(options => 
     options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.AddScoped<IUnitOfWork, UnitOfWork>();
builder.Services.AddRazorPages().AddRazorRuntimeCompilation();

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();

app.MapControllerRoute(
   name: "default",
   pattern: "{area=Customer}/{controller=Home}/{action=Index}/{id?}");
app.Run();
c# asp.net asp.net-core http-status-code-404
3个回答
1
投票

您应该在 Areas/Customer/Controllers 文件夹中有一个 HomeController。控制器应该有一个操作 Index,并且在 Areas/Customer/Views 文件夹中应该有一个名为 Index 的视图。您正在映射到该位置,但从上面我看不到您有这个:Areas/Customer/Controllers/HomeController。 检查区域文件夹结构 - https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/areas?view=aspnetcore-6.0


0
投票

我添加到 HomeController 并且它开始工作。

[Area("Customer")]

Area 很奇怪,因为它之前在没有属性的情况下工作。


0
投票

尝试改变这一点:

builder.Services.AddRazorPages().AddRazorRuntimeCompilation();

对此,看看它是否有什么不同:

builder.Services.AddRazorPages();
© www.soinside.com 2019 - 2024. All rights reserved.