I see this question out there. but the answer doesn't work for me.
I created an empty asp.net website. .NET 4.5
I installed the sample in nuget via Install-Package Microsoft.AspNet.Identity.Sample -pre
I could not get the initializer to run. so i the did the following
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
Database.SetInitializer<ApplicationDbContext>(new ApplicationDbInitializer());
this.Database.Initialize(true);
}
static ApplicationDbContext()
{
// Set the database intializer which is run once during application start
// This seeds the database with admin user credentials and admin role
//
}` `
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
The Rolemanager is always null. I tried the other answers but they never worked. I did not change the sample other than what is shown above. So why doesn't it work? the db and the tables are created tho. the rolemanager is used below and is null.
public static void InitializeIdentityForEF(ApplicationDbContext db)
{
var userManager = HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>();
var roleManager = HttpContext.Current.GetOwinContext().Get<ApplicationRoleManager>();
const string name = "admin@example.com";
const string password = "Admin@123456";
const string roleName = "Admin";
//Create Role Admin if it does not exist
var role = roleManager.FindByName(roleName);
if (role == null)