【问题标题】:添加身份脚手架
【发布时间】:2022-01-23 05:59:43
【问题描述】:

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

以下是添加 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();

【问题讨论】:

  • 能看看有没有这个页面Customer/Home吗?
  • 我添加了属性区域,它解决了问题

标签: c# asp.net asp.net-core http-status-code-404


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    我添加到 HomeController 并开始工作。

    [Area("Customer")]
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-02
      • 2020-11-23
      • 1970-01-01
      • 2023-01-04
      • 2020-04-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多