3
//Creates the admin ROLE
new RoleSeed(app.ApplicationServices.GetService<RoleManager<IdentityRole>>()).Seed().GetAwaiter().GetResult();
//Creates the admin ACCOUNT
new AccountSeed(app.ApplicationServices.GetService<UserManager<ApplicationUser>>()).Seed().GetAwaiter().GetResult();
//Adding ACCOUNT to ROLE
new AccToRoleSeed(app.ApplicationServices.GetService<UserManager<ApplicationUser>>(),
app.ApplicationServices.GetService<ApplicationDbContext>()).Seed().GetAwaiter().GetResult();
这段代码生成一个Admin角色帐户并最终将该帐户添加到管理员角色。 过去,这工作之前,我已经升级到2.0.0在Startup.cs中生成角色在.NET Core 2.0中不起作用
现在我得到这个错误:
System.InvalidOperationException occurred HResult=0x80131509
Message=Cannot resolve scoped service 'Microsoft.AspNetCore.Identity.RoleManager`1[Microsoft.AspNetCore.Identity.IdentityRole]' from root provider.
这怎么能在此版本中做了什么?谢谢!
这可能对您有所帮助。请检查https://wildermuth.com/2017/07/06/Program-cs-in-ASP-NET-Core-2-0 – immirza
谢谢!我使用Program.cs的.net 1.1方式,明确的方式,现在一切正常! – FabiGhenof