所以我正在尝试使用以下初始化程序播种我的数据库
public class DbInitializer : DropCreateDatabaseAlways<IAMContext>
{
protected override void Seed(IAMContext context)
{
WebSecurity.InitializeDatabaseConnection("IAMContext",
"UserProfile", "UserId", "UserName", autoCreateTables: true);
var roles = Roles.Provider;
var membership = Membership.Provider;
if (!roles.RoleExists("Admin"))
{
roles.CreateRole("Admin");
}
if (!WebSecurity.UserExists("test"))
{
WebSecurity.CreateUserAndAccount("test", "password");
}
if (!roles.GetRolesForUser("test").Contains("Admin"))
{
roles.AddUsersToRoles(new[] { "test" }, new[] { "admin" });
}
context.Products.Add(new Product
{
Id = 1,
Name = "Homunculi",
Price = 85,
LongDescription = "Happens when failed human transmutations occur",
ShortDescription = "Failed Xmute",
media = "CD"
});
base.Seed(context);
}
}
我总是得到我必须首先调用 WebSecurity.InitializeDatabaseConnection 的异常。看起来我已经有了,所以我有点困惑。任何帮助都会很棒。我应该提到我是 webforms 身份验证的新手。感谢您的理解和解答!