Skip to content

ASP.NET Core Identity by default uses string as primary key, using GuIdentity you will have guid as a primary key.

License

Notifications You must be signed in to change notification settings

msmaldi/GuIdentity

Repository files navigation

ASP.NET Core GuIdentity

ASP.NET Core Identity by default uses string as primary key, using GuIdentity you will have guid as a primary key.

Usage

Based in project generated by dotnet new mvc --auth Individual

  1. Run:

    dotnet add package Msmaldi.AspNetCore.GuIdentity.EntityFrameworkCore --version 3.0.0

  2. Create a file User.cs add like:

    using Msmaldi.AspNetCore.GuIdentity;
    
    namespace GuIdentitySample.Mvc.Models
    {
    	public class User : GuIdentityUser
    	{        
    	}
    }
  3. In file ApplicationDbContext.cs add and change:

    using Msmaldi.AspNetCore.GuIdentity.EntityFrameworkCore;
    public class ApplicationDbContext : GuIdentityDbContext<User>
  4. In file Startup.cs add and change:

    using Msmaldi.AspNetCore.GuIdentity;
    services.AddDefaultIdentity<User>()
    		.AddEntityFrameworkStores<ApplicationDbContext>();

    or if you need use GuIdentityRole and RoleManager

    services.AddIdentity<User, GuIdentityRole>()
    		.AddEntityFrameworkStores<ApplicationDbContext>()
    		.AddDefaultTokenProviders();
  5. In file /Views/Shared/_LoginPartial.cshtml:

    @inject SignInManager<User> SignInManager
    @inject UserManager<User> UserManager
  6. Delete app.db:

    rm app.db

  7. Delete folder:

    rm -r ./Data/Migrations

  8. Run:

    dotnet tool install --global dotnet-ef
    
    dotnet ef migrations add CreateGuIdentityInitialSchema -o ./Data/Migrations
    
    dotnet ef database update
    
    dotnet run
    

About

ASP.NET Core Identity by default uses string as primary key, using GuIdentity you will have guid as a primary key.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages