我想在ASP.NET 5 MVC上創建項目,所以我想添加超級用戶到我的數據庫。在ASP.NET MVC 4我Configuration.cs文件在我的移民文件夾,我用這個代碼在種方法來創建超級用戶:Configuration.cs文件asp.net 5 mvc
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" });
}
}
}
但我無法找到我的新項目相同的文件。
some1能幫我嗎?謝謝。