我在使用控制器创建管理员用户时遇到问题。这里有什么问题?这是我的代码:public class ProductsController : Controller{ private SwagExchangeDb db = new SwagExchangeDb(); protected override void Initialize(RequestContext requestContext) { var ac = new ApplicationDbContext(); var userManager = new ApplicationUserManager(new UserStore<ApplicationUser>(ac)); var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(ac)); var user = new ApplicationUser { UserName = "hello@gmail.com", Email = "hello@gmail.com"}; userManager.Create(user, "Hello1234!"); roleManager.Create(new IdentityRole("admin")); userManager.AddToRole(user.Id, "admin"); }出现错误:System.InvalidOperationException:'找不到用户ID。
1 回答
- 1 回答
- 0 关注
- 96 浏览
添加回答
举报
0/150
提交
取消