I am trying to create project on ASP.NET 5 MVC, so I want to add superuser to my db. In ASP.NET 4 MVC I had Configuration.cs file in my migration folder and I use this code to create superuser in Seed method:
namespace WebApp.Migrations
{
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
using WebApp.Models;
internal sealed class Configuration : DbMigrationsConfiguration<WebApp.Models.ApplicationDbContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
// AutomaticMigrationsEnabled = true;
// AutomaticMigrationDataLossAllowed = true;
}
protected override void Seed(WebApp.Models.ApplicationDbContext context)
{
// This method will be called after migrating to the latest version.
var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
var user = new ApplicationUser()
{
UserName = "***",
Email = "***",
Guid="0",
EmailConfirmed = true
};
manager.Create(user, "***");
if (roleManager.Roles.Count() == 0)
{
roleManager.Create(new IdentityRole { Name = "admin" });
}
var adminUser = manager.FindByName("***");
manager.AddToRoles(adminUser.Id, new string[] { "admin" });
}
}
}
But I can't find the same file in my new project.
Can some1 help me? Thx.
