Reputation: 3527
I'm working on the ASP.NET Identity. By default, the AspNetUsers table
comes with a few columns such as: ID, UserName, HashPassword, Email, EmailConfirmed, Phone
etc.
By default, the ID
column is the Primary Key
and UserName
has the Unique Constraint
.
How do I make other fields such as Email
and/or Phone
to have the same unique constraint
as the UserName
?
What I have done so far:
I manage to add the unique constraint to the database manually, however, unlike the UserName
field, I was unable to do the validation on the application level. For example: The UserName
field will display the error message "Name XXX is already taken" if the user tries to register an account with the same username.
Upvotes: 4
Views: 2677
Reputation: 28200
To enforce uniqueness at the UserManager layer, you can implement your own IUserValidator and check for your custom uniqueness rules
Upvotes: 1