Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Use AspNet.Identity core in My Sql database

I am developing one application using asp dot net core 2 using MySql database.Please help me How can i use Asp Net Identity in MySqlDatabase.

like image 572
Rony Patel Avatar asked Sep 19 '17 10:09

Rony Patel


People also ask

Can you use MySQL with .NET Core?

NET Core and MySQL are both free and open source technologies. The new ASP.NET Core can run on Linux and in Linux Containers, and MySQL is one of the easiest databases to get started with. This makes the combination of ASP.NET Core and MySQL a pretty compelling combination.

Can ASP Net connect to MySQL?

To Connect to a MySQL Database Using ASP.NETFind your database's connection strings (Plesk). Note: Change the your password value to your real database password value. Using Microsoft Visual Studio . NET create an ASP.NET Project.

How does core identity work in asp net?

ASP.NET Core Identity provides a framework for managing and storing user accounts in ASP.NET Core apps. Identity is added to your project when Individual User Accounts is selected as the authentication mechanism. By default, Identity makes use of an Entity Framework (EF) Core data model.


1 Answers

You Can create an Identity Database along with your MySQL Database and use the Identity database for your authorization

This is how I do it.

   //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"));

This should work fine along with your MySQL DB

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

    }


}
like image 115
ma1169 Avatar answered Oct 06 '22 00:10

ma1169