I'm trying to set up some seed data for my MVC 5 web application, but it doesn't seem to be created for IdentityUser. When I check the App_Data folder, it is empty (Show all files included)
Here is my WebAppDatabaseInitializer.cs
public class WebAppDatabaseInitializer : DropCreateDatabaseIfModelChanges<WebAppDbContext>
{
protected override void Seed(WebAppDbContext context)
{
var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
var RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
string name = "Admin";
string password = "123456";
string test = "test";
RoleManager.Create(new IdentityRole(test));
UserManager.Create(new ApplicationUser() { UserName = test });
if (!RoleManager.RoleExists(name))
{
var roleresult = RoleManager.Create(new IdentityRole(name));
}
var user = new ApplicationUser();
user.UserName = name;
var adminresult = UserManager.Create(user, password);
if (adminresult.Succeeded)
{
var result = UserManager.AddToRole(user.Id, name);
}
base.Seed(context);
}
}
and my Global.asax.cs
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
Database.SetInitializer(new WebAppDatabaseInitializer());
}
}
any ideas what could be wrong?
source
share