【问题标题】:Error when using Custom User class inherited from IdentityUser使用从 IdentityUser 继承的自定义用户类时出错
【发布时间】:2019-04-23 20:50:25
【问题描述】:

我正在使用 asp.net core 2.2。 为从 IdentityUser 继承的应用程序用户使用自定义类时,注册和密码登录失败,并显示消息“SqlException:无效的列名 'ApplicationUserId'”。

Statrup.cs

 services.AddIdentity<ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();

应用程序用户类

 public class ApplicationUser : IdentityUser
 {  
 }

数据库是标准身份生成的,没有添加自定义列。

【问题讨论】:

  • 您是否已运行迁移并更新数据库以同步您的模型和数据库?是否有任何详细步骤可以重现您的问题?对于错误消息,您使用了 .net core 2.0 标识中的 AccountController。对于 .net core 2.2,默认标识是带有 LoginModel 的库。您是否从 .net core 2.0 迁移到 .net core 2.2?

标签: asp.net-core asp.net-identity basic-authentication


【解决方案1】:

尝试像这样修改您的 ApplicationDbContext:

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
        {
        }
    }

您的默认 ApplicationDbContext 使用 IdentityUser 作为其用户存储,而不是 ApplicationUser

【讨论】:

    猜你喜欢
    • 2021-05-12
    • 2023-03-16
    • 1970-01-01
    • 2013-06-05
    • 1970-01-01
    • 2015-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多