繁体   English   中英

如何在Azure中发布支持身份(单个用户帐户)的我的MVC应用程序?

[英]How published in Azure my MVC App with support for Identity (Individual User Accounts)?

我正在开发一个支持“个人用户帐户”的MVC应用程序。 我的本地应用程序正常运行。 它正确生成数据库,我的代码...

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中,它不生成,为什么?

我该怎么办?

使用迁移? ...我该怎么做

如果您面临在Azure上进行数据库部署的问题,请查看本文,并按照具有有关在Azure上发布本地数据库的详细信息的步骤进行操作

http://www.asp.net/mvc/overview/getting-started/database-first-development/publish-to-azure

在此处输入图片说明

在Azure的发布向导中您是否完成了以下操作

我在azure上手动创建了数据库,然后在发布操作期间使用了web.config转换选项来修改数据库连接字符串。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM