小编rob*_*_rg的帖子

布局不适用于用户配置文件的 asp.net core 3.0

在 Asp core 3.0 上,当用户单击他们的个人资料“Areas/Identity/Pages/Account/Manage/_layout.cshtml”时,我的布局页面对用户不起作用

当我登录后单击默认电子邮件时,我得到 Manage/Index.cshtml 但没有布局详细信息。像导航一样,忘记密码等的链接没有显示。我不知道是什么导致了这种情况。

我把它放在其他项目上,看到了任何差异,也找不到我的布局不显示的任何原因。

区域/身份/页面/帐户/管理/_layout.cshtml

@{
Layout = "/Areas/Identity/Pages/_Layout.cshtml";
 }
Run Code Online (Sandbox Code Playgroud)

Areas/Identity/Pages/Account/Manage/Index.cshtml

@page
@model IndexModel
@{
  ViewData["Title"] = "Profile";
  ViewData["ActivePage"] = ManageNavPages.Index;
}
Run Code Online (Sandbox Code Playgroud)

区域/身份/页面/帐户/_ViewStart.cshtml

@{
Layout = "/Views/Shared/_Layout.cshtml";
}
Run Code Online (Sandbox Code Playgroud)

试图查看我遗漏了什么或任何其他要检查的地方以显示布局页面。

在此处输入图片说明

在此处输入图片说明

asp.net asp.net-mvc asp.net-core

6
推荐指数
2
解决办法
4026
查看次数

无法为“IdentityUser”创建 DbSet,因为该类型未包含在上下文的模型中

尝试所有代码来让所有用户了解他们的角色,因此我不得不稍微更改我的代码并遇到此错误。我不确定我做错了什么,我将其范围缩小到我的startup.cs和ApplicationDBContect类。我没有错误,我可能需要迁移,但还没有这样做以防止引起更多问题。

我参考了Stackoverflow 问题并遇到了其他错误。

应用程序DBContext.cs

public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string, IdentityUserClaim<string>,
ApplicationUserRole, IdentityUserLogin<string>,
IdentityRoleClaim<string>, IdentityUserToken<string>>
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
       : base(options)
    {
    }
    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        builder.Entity<ApplicationUserRole>(userRole =>
        {
            userRole.HasKey(ur => new { ur.UserId, ur.RoleId });

            userRole.HasOne(ur => ur.Role)
                .WithMany(r => r.UserRoles)
                .HasForeignKey(ur => ur.RoleId)
                .IsRequired();

            userRole.HasOne(ur => ur.User)
                .WithMany(r => r.UserRoles)
                .HasForeignKey(ur => ur.UserId)
                .IsRequired();
        });
    }

    public DbSet<ApplicationUser> ApplicationUser { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

启动.cs

services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(
                Configuration.GetConnectionString("DefaultConnection"))); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

asp.net-core ×2

asp.net ×1

asp.net-mvc ×1

c# ×1