C# .NET Core UserManager CreateAync将用户名/电子邮件/电话号码始终保留为空

C# .NET Core UserManager CreateAync将用户名/电子邮件/电话号码始终保留为空,c#,sql,asp.net-core,.net-core,asp.net-identity,C#,Sql,Asp.net Core,.net Core,Asp.net Identity,NET核心应用程序实现了一些额外字段的自定义identyuser逻辑 我已经设法使用CreateAsync创建了一个用户,但是UserName、Email和PhoneNumber字段总是被忽略。它们的规范化版本(NormalizedUserName、NormalizedEmail和NormalizedPhoneNumber(最后一个版本由我创建,因为任何不可空值都必须是唯一的))创建成功,但始终大写 控制器代码: [HttpPost] [AllowAnonymous] [Route("Regis

NET核心应用程序实现了一些额外字段的自定义
identyuser
逻辑

我已经设法使用
CreateAsync
创建了一个用户,但是
UserName
Email
PhoneNumber
字段总是被忽略。它们的规范化版本(
NormalizedUserName
NormalizedEmail
NormalizedPhoneNumber
(最后一个版本由我创建,因为任何不可空值都必须是唯一的))创建成功,但始终大写

控制器代码:

[HttpPost]
[AllowAnonymous]
[Route("Registration")]
public async Task<IActionResult> UserRegistration(ApplicationUserModel model)
{
    var applicationUser = new ApplicationUser()
    {
        UserName = model.UserName,
        Email = model.Email,
        PhoneNumber = model.PhoneNumber,
        FirstName = model.FirstName,
        // Other fields that are being inserted normally...
    };

    IdentityResult result = await _userManager.CreateAsync(applicationUser, model.Password);

    try
    {
        return Ok(result);
    }
    catch (Exception ex)
    {
        throw ex;
    }
}
我在
Startup.cs
中也有此代码:

services.Configure<IdentityOptions>(options => {
    options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
    options.User.RequireUniqueEmail = true;
    options.Password.RequireDigit = true;
    options.Password.RequireLowercase = true;
    options.Password.RequireUppercase = true;
    options.Password.RequiredLength = 8;
    options.Password.RequireNonAlphanumeric = false;
});
services.Configure(选项=>{
options.User.AllowedUserNameCharacters=“abcdefghijklmnopqrstuvwxyzabefghijklmnopqrstuvwxyzo123456789-”;
options.User.RequireUniqueEmail=true;
options.Password.RequireDigit=true;
options.Password.RequireLowercase=true;
options.Password.RequireUppercase=true;
options.Password.RequiredLength=8;
options.Password.RequireNonAlphanumeric=false;
});

如何将相应的值与其余值一起插入数据库?

添加自定义属性后,应在ConfigureServices中使用新的
ApplicationUser

services.AddDefaultIdentity<ApplicationUser>()
        .AddDefaultUI(UIFramework.Bootstrap4)
        .AddEntityFrameworkStores<ApplicationDbContext>();
并确认在控制器中向UserManager注入新的ApplicationUser:

private readonly UserManager<ApplicationUser> _userManager;
private readonly UserManager\u UserManager;

最后,
addmigration xx
updatedatabase
让ef在
AspNetUsers
表中创建列

这正是我所需要的我不知道如何感谢你但我真的很想我终于可以继续前进了!我所要做的就是用您的解决方案替换
AddEntityFrameworks
。非常感谢你!
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
private readonly UserManager<ApplicationUser> _userManager;