【发布时间】:2016-10-03 22:13:44
【问题描述】:
我正在尝试使用初始用户和用户角色为我的数据库播种,但在这样做时遇到了问题。在查看了关于 SO 的类似帖子后,我在种子方法中得到了以下结果:
if (!context.Users.Any(u => u.UserName == "founder"))
{
var store = new UserStore<ApplicationUser>(context);
var manager = new UserManager<ApplicationUser>(store);
var user = new ApplicationUser {UserName = "founder"};
manager.Create(user, "ChangeItAsap!");
manager.AddToRole(user.Id, "AppAdmin");
}
还有我的 ApplicationUser 类:
public class ApplicationUser : IdentityUser<int, CustomUserLogin,CustomUserRole,CustomUserClaim>
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser, int> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
我的问题是我在 ApplicationUser 上遇到编译错误,这样说
RecipeManager.Models.ApplicationUser 类型不能用作泛型类型或方法
'UserManager<TUser>'中的类型参数“TUser”。没有从RecipeManager.Models.ApplicationUser到Microsoft.AspNet.Identity.IUser<string>的隐式引用转换
【问题讨论】:
标签: c# asp.net-mvc seeding