I need to create a user with UserName, FirstName and LastName and Email fields. I'm using Mysql database and Pomelo package. Migration and DB update are working fine.
This code results in failure.
public async Task<IActionResult> CreateUserAsync()
{
var user = new ApplicationUser(
UserName: "blablabla",
FirstName: "blablabla",
LastName: "blablabla",
Email: "[email protected]"
);
var successful = await mUserManager.CreateAsync(user
, "Pasword123456#");
if(successful.Succeeded)
return Content("User was created", "text/html");
return Content("User created FAILED", "text/html");
}
}
The table in the database is empty
+-----------------------+ | Tables_in_calendario | +-----------------------+ | __efmigrationshistory | | aspnetroleclaims | | aspnetroles | | aspnetuserclaims | | aspnetuserlogins | | aspnetuserroles | | aspnetusers
| | aspnetusertokens | | events | | usuarios
| +-----------------------+ mysql> select * from aspnetusers; Empty set (0.00 sec)
I have no idea how to make it work.
In debug mode that is the only information I have.
I found out the problem.
I was overwriting Email and UserName in ApplicationUser.
This was the warning in the building.
The solution was simply removing the fields.
In the Configure service You can do this where AppUser class is inherited from IdentityUser, you can use it directly also
services.AddIdentityCore<AppUser>(opt =>
{
opt.Password.RequireDigit = false;
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With