【问题标题】:ASP.NET Core 2.1 Identity couldn't find ApplicationUserASP.NET Core 2.1 Identity 找不到 ApplicationUser
【发布时间】:2019-01-31 14:45:57
【问题描述】:

我已将 Identity 包含到我的 .NET Core2.1 项目中,当我尝试构建项目时,它会警告我以下错误:

找不到类型或命名空间名称“ApplicationUser”(您是否缺少 using 指令或程序集引用?)

我应该自己定义 ApplicationUser 还是 Identity 自己创建它?

任何帮助将不胜感激。

【问题讨论】:

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


    【解决方案1】:

    您必须自己创建 ApplicationUser 类。默认用户是 IdentityUser。 ApplicationUser 继承自 IdentityUser:

    public class ApplicationUser : IdentityUser
    {
    }
    

    但是,如果您不扩展 ApplicationUser,那么您也可以使用 IdentityUser。所以不要这样:

    services.AddIdentity<ApplicationUser, IdentityRole>()
    

    你可以用这个:

    services.AddIdentity<IdentityUser, IdentityRole>()
    

    并将整个项目的其余部分中的 ApplicationUser 替换为 IdentityUser。

    猜你喜欢
    • 2018-11-23
    • 2015-06-19
    • 2019-03-03
    • 1970-01-01
    • 2018-12-05
    • 2019-04-17
    • 1970-01-01
    • 2019-02-25
    相关资源
    最近更新 更多