必须指定至少一个角色

时间:2019-08-30 15:26:06

标签: entity-framework asp.net-core-mvc asp.net-identity

我在asp.net MVC核心应用程序中使用asp.net身份,运行该应用程序(ctrl + F5)时出现此错误。

  

InvalidOperationException:必须至少指定一个角色。   Microsoft.AspNetCore.Authorization.Infrastructure.RolesAuthorizationRequirement..ctor(IEnumerable allowedRoles)

我的dbContext类appdbcontextClass和扩展类

public class ApppDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApppDbContext(DbContextOptions<ApppDbContext> options) : base(options)
        {
            //options.
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<Employee>().HasData(
                new Employee
                {
                    Id = 2,
                    Name = "Mark",
                    Department = Department.IT,
                    Email = "abc@gmail.com"
                }
                );
        }

        public DbSet<Employee> Employees { get; set; }

    }

扩展类

  public class ApplicationUser:IdentityUser
    {
        public string City { get; set; }
    }

0 个答案:

没有答案