web-dev-qa-db-ja.com

My SQLデータベースでAspNet.Identityコアを使用する方法

asp dot net core 2を使用して1つのアプリケーションを開発していますMySqlデータベースMySqlDatabaseAsp Net Identityを使用するにはどうすればよいですか?.

7
Rony Patel

私はクライアントのためにこれをしなければなりませんでした。また、ASP.NET Core 1.0でアプリケーションを作成しましたが、好奇心から、.NET Core 2.0のアプリケーションも試してみました。

私がしたことは、最初にパッケージマネージャーコンソールを使用して https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql/ からEntity Framework MySQLパッケージをインストールすることでした。

その後、startup.cs、メソッドConfigureServices、オプションUseSqlServerからUseMySqlへ、以下の画像のように。

enter image description here

私のappsettings.jsonには、次のようにIdentityConnectionという名前のMySQL接続があります。

{
    "ConnectionStrings": {
        "IdentityConnection": "Server=127.0.0.1;Database=identitycoredb;Uid=root;Pwd=1234;"
    },

IDテーブルを作成するには、パッケージマネージャーコンソールで移行コマンドを実行しました。

EntityFrameworkCore\Update-Database -Verbose

enter image description here

18
Tiago Ávila

編集:現時点では、.Net Core 2.0はMySqlでIdentityをサポートしていません。近い将来、再びサポートされる可能性があります。

__

Entity FrameworkとMySQLをPomeloの接続で接続する必要があり、Identityが機能するはずです。これをチェックしてください-> https://damienbod.com/2016/08/26/asp-net-core-1-0-with-mysql-and-entity-framework-core/

3
Claudio

MySQLデータベースと一緒にIDデータベースを作成し、認証にIDデータベースを使用できます

これが私のやり方です。

   //MySQL Database 
     services.AddDbContext<EFDbContext>(options =>
                options.UseSqlServer("Server = ; Database =MySQL  ; Trusted_Connection = True; MultipleActiveResultSets = true"));
//Identity Database               
     services.AddDbContext<EFIdentityDbContext>(options =>
                    options.UseSqlServer("Server = ; Database = Identity; Trusted_Connection = True; MultipleActiveResultSets = true"));

これはMySQL DBと一緒にうまく機能するはずです。

public class EFIdentityDbContext : IdentityDbContext
{
    public EFIdentityDbContext(DbContextOptions<EFIdentityDbContext> options )
        :base (options)
    {

    }


}
1
ma1169