I am creating a User using ASP.NET Core Identity as follows:
User user = new User {
Email = "[email protected]",
Name = "John"
};
await manager.CreateAsync(user, "JohnPass");
I get an error saying the Username is invalid because it is null.
How to configure Identity to use the Email as Username?
Or do I need to manually set the Username equal to the Email?
Use below code based on mandatory items
User user = new User {
Id = id,// some auto generated id
Email = "[email protected]",
UserName = "[email protected]",// because you want to keep email id as UserName
DisplayName= "John"
};
await manager.CreateAsync(user, "JohnPass");
One potential issue with this approach is that if we keep email as 'User Name', then in some cases, it may not allow the user to change their email id in the future.
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