从DOTNET新的web应用--auth个人-o定制IdentityUser

问题描述 投票:0回答:2

我学习C#和DOTNET核心,我目前工作的模板

    dotnet new webapp --auth Individual -o WebApp1

但是,它的很多东西对我说,我不明白幕后。

我翻箱倒柜代码找到如何登录视图中创建和处理,但有没有这样的运气。目前,我试图将列添加到该模板给出数据库,显示我想在这里:

services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlite(
                Configuration.GetConnectionString("DefaultConnection")));
        services.AddDefaultIdentity<IdentityUser>()
            .AddEntityFrameworkStores<ApplicationDbContext>();
c# asp.net-core
2个回答
0
投票

该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> 
{
    ...
}

0
投票

IdentityUser是身份基地“用户”类,所以它的填充,在因此不需要额外的努力,需要你的一部分。那很好,如果你不想给定制用户,但因为你明明做,只是简单地创建自己的类,从IdentityUser派生:

public class MyUser : IdentityUser
{
    public string Foo { get; set; }
}

然后,使用自定义用户类,以代替IdentityUser的Param类型:

services.AddDefaultIdentity<MyUser>()
© www.soinside.com 2019 - 2024. All rights reserved.