Dot-Net
ASP.NET Core 2.1 Identity 找不到 ApplicationUser
我已將 Identity 包含到我的 .NET Core2.1 項目中,當我嘗試建構項目時,它會警告我以下錯誤:
找不到類型或命名空間名稱“ApplicationUser”(您是否缺少 using 指令或程序集引用?)
我應該自己定義 ApplicationUser 還是 Identity 會自己創建它?
任何幫助,將不勝感激。
您必須自己創建 ApplicationUser 類。預設使用者是 IdentityUser。ApplicationUser 繼承自 IdentityUser:
public class ApplicationUser : IdentityUser { }但是,如果您不擴展 ApplicationUser,那麼您也可以使用 IdentityUser。所以代替這個:
services.AddIdentity<ApplicationUser, IdentityRole>()你可以使用這個:
services.AddIdentity<IdentityUser, IdentityRole>()並在整個項目的其餘部分中用 IdentityUser 替換 ApplicationUser。