我正在开发支持“个人用户帐户”的MVC应用程序。我的本地App正常工作。 它正确生成数据库,我的代码......
IdentityModels.cs
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
Database.SetInitializer<ApplicationDbContext>(new InitTaxiMetroUserDb());
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
public class InitTaxiMetroUserDb : CreateDatabaseIfNotExists<ApplicationDbContext>
{
protected override void Seed(ApplicationDbContext context)
{
context.Configuration.LazyLoadingEnabled = true;
if (context.Users.Any(u => u.UserName == "admin"))
return;
var store = new UserStore<ApplicationUser>(context);
var userManager = new UserManager<ApplicationUser>(store);
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
if (!roleManager.RoleExists("Administrador"))
roleManager.Create(new IdentityRole("Administrador"));
if (!roleManager.RoleExists("Flota"))
roleManager.Create(new IdentityRole("Flota"));
if (!roleManager.RoleExists("Gestor"))
roleManager.Create(new IdentityRole("Gestor"));
if (!roleManager.RoleExists("Conductor"))
roleManager.Create(new IdentityRole("Conductor"));
var user = new ApplicationUser { UserName = "admin" };
var result = userManager.Create(user, "123456");
if (result.Succeeded)
userManager.AddToRole(user.Id, "Administrador");
user = new ApplicationUser { UserName = "xxxxx@gmail.com" };
result = userManager.Create(user, "123456");
if (result.Succeeded)
userManager.AddToRole(user.Id, "Gestor");
user = new ApplicationUser { UserName = "yyyyy@yahoo.es" };
result = userManager.Create(user, "123456");
if (result.Succeeded)
userManager.AddToRole(user.Id, "Conductor");
base.Seed(context);
}
}
的Web.config
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=TaxiMetroUserDb;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\TaxiMetroUserDb.mdf" providerName="System.Data.SqlClient" />
问题是当我想在Azure上发布此应用程序时:不会生成我无法执行身份验证的此数据库。数据库在Azure中不存在,它不会生成,为什么??
我该怎么做?
使用迁移? ......我怎么做呢
答案 0 :(得分:0)
如果您在Azure上面临数据库部署,请查看本文并按照具有有关在Azure上发布本地数据库的详细信息的步骤进行操作
http://www.asp.net/mvc/overview/getting-started/database-first-development/publish-to-azure
您是否在azure
的发布向导中完成了以下操作答案 1 :(得分:0)
我在azure上手动创建了数据库,然后使用web.config转换选项在发布操作期间修改数据库连接字符串。