我学习C#和DOTNET核心,我目前工作的模板
dotnet new webapp --auth Individual -o WebApp1
但是,它的很多东西对我说,我不明白幕后。
我翻箱倒柜代码找到如何登录视图中创建和处理,但有没有这样的运气。目前,我试图将列添加到该模板给出数据库,显示我想在这里:
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
该DOTNET核心团队决定在剃刀库认证抽象的默认UI,寻找一个依赖 - > SDK - > Microsoft.AspNetCore.App - > Microsoft.AspNetCore.Identity.UI
看看代码此包here
这应该给你一个什么样的背景实际上是怎么回事的想法。
至于延伸的用户模型
public class CustomUser : IdentityUser
{
//custom properties
}
然后你要配置身份中间件认识到这一点,作为用户的主力机型。
services.AddDefaultIdentity<CustomUser>();
不要忘了,这样可以创建正确的表来更新数据库继承。
public class ApplicationDbContext : IdentityDbContext<CustomUser>
{
...
}
IdentityUser
是身份基地“用户”类,所以它的填充,在因此不需要额外的努力,需要你的一部分。那很好,如果你不想给定制用户,但因为你明明做,只是简单地创建自己的类,从IdentityUser
派生:
public class MyUser : IdentityUser
{
public string Foo { get; set; }
}
然后,使用自定义用户类,以代替IdentityUser
的Param类型:
services.AddDefaultIdentity<MyUser>()