csharp 为ASP CORE 2_2配置IIdentyUser

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 为ASP CORE 2_2配置IIdentyUser相关的知识,希望对你有一定的参考价值。

// 1. Create a model that inherit from Microsoft.AspNetCore.Identity.IdentityUser

public class User : Microsoft.AspNetCore.Identity.IdentityUser
  {
    public string Nom { get; set; }
    public string Prenom { get; set; }
  }
  
  // 2.Create a datacontext that inherits from typed IdentityDbContext<User>
  public class DataContext : IdentityDbContext<User>
  {
    public DataContext(DbContextOptions options) : base(options)
    {

    }
  }
  
  // 3. COnfigure startup file
  services.AddIdentity<User, IdentityRole>(conf =>
			{
				conf.User.RequireUniqueEmail = true;
				conf.Password.RequiredLength = 6;
			}).AddEntityFrameworkStores<DataContext>().AddDefaultTokenProviders();
			
	// class to be injected in order to access the store
	UserManager<User>, UserRole<User>
	
//apply migration
add-migration MyFirstMigration
Update-Database
	
dotnet ef migrations add MyFirstMigration
dotnet ef database update

以上是关于csharp 为ASP CORE 2_2配置IIdentyUser的主要内容,如果未能解决你的问题,请参考以下文章

csharp 强类型配置文件ASP CORE 2_2

csharp ASP.NET Core - Json序列化程序设置枚举为字符串并忽略空值

为 HTTPS 配置 ASP.NET Core 2.0 Kestrel

ASP.NET Core 一步步搭建个人网站_环境搭建

csharp TimedLogger ASP.NET CORE

ASP.NET Core 2 中的问题配置选项