gpt4 book ai didi

c# - 无法在 web-api 2 中创建新用户

转载 作者:行者123 更新时间:2023-11-30 18:31:32 25 4
gpt4 key购买 nike

在我的 asp.net web-api 2 项目中收到对 api/accounts/POST 请求时,我正在尝试创建一个新用户。

尝试 1:创建 Identity User

我已经完全按照项目模板中显示的那样进行了尝试:

// Inside Post() method
IdentityUser newUser = new IdentityUser()
{
UserName = "username",
};
IdentityResult result = await this.UserManager.CreateAsync(newUser, "password");

System.Data.Entity.Core.UpdateException: Cannot insert the value NULL into column 'Discriminator', table 'MyDb.dbo.AspNetUsers'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated.

尝试 2:创建一个用户

我还尝试添加我的 IdentityUser 子类版本:

// Definition
public class User : IdentityUser
{
public User() { }
}

// Inside Post() method
User newUser = new User()
{
UserName = userDto.Email,
};
IdentityResult result = await this.UserManager.CreateAsync(newUser, "password");

System.InvalidOperationException: Mapping and metadata information could not be found for EntityType 'MyProject.Data.User'.

它最初是工作的,但我不明白为什么它不再工作了。最初我在我的用户对象(名字、姓氏)上添加了两个字段,但删除它们后我仍然遇到问题。

最佳答案

对于 asp identity 2.2,Discriminator 列已从数据库中删除您可以迁移数据库或只是删除列

关于c# - 无法在 web-api 2 中创建新用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19969421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com