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