seed users and roles asp.net mvc 5 from startup code example
Example: .net identity seed users and roles
public static void Main(string[] args)
{
var host = BuildWebHost(args);
using (var scope = host.Services.CreateScope())
{
var serviceProvider = scope.ServiceProvider;
try
{
var userManager = serviceProvider.
GetRequiredService<UserManager<MyIdentityUser>>();
var roleManager = serviceProvider.
GetRequiredService<RoleManager<MyIdentityRole>>();
MyIdentityDataInitializer.SeedData
(userManager, roleManager);
}
catch
{
}
}
host.Run();
}