ASP.NET Core 2.1 Identity 找不到 ApplicationUser

ASP.NET Core 2.1 Identity couldn't find ApplicationUser

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

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

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

如有任何帮助,我们将不胜感激。

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

public class ApplicationUser : IdentityUser
{
}

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

services.AddIdentity<ApplicationUser, IdentityRole>()

你可以使用这个:

services.AddIdentity<IdentityUser, IdentityRole>()

并用 IdentityUser 替换项目其余部分的 ApplicationUser。