我正在使用ASP.NET Core Identity创建一个用户,如下所示:
User user = new User {
Email = "john@domain.com",
Name = "John"
};
await manager.CreateAsync(user, "JohnPass");
我收到一条错误消息,指出用户名无效,因为它为空。
如何配置身份以使用电子邮件作为用户名?
或者我是否需要手动设置用户名等于电子邮件?
答案 0 :(得分:2)
根据强制性项目使用以下代码
User user = new User {
Id = id,// some auto generated id
Email = "john@domain.com",
UserName = "john@domain.com",// because you want to keep email id as UserName
DisplayName= "John"
};
await manager.CreateAsync(user, "JohnPass");