我在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; }
}