How does one prevent duplicate email addresses while users modify their email addresses after registration using the default MVC Membership Provider?
asp.net-membership, asp.net-mvc, membership-provider
Solution
You can search for an existing username by that email:
String userName = MembershipProvider.GetUserNameByEmail(email)
If no match is found, `userName` will be null. See here for more info on this.
Also, if your MembershipProvider has `RequiresUniqueEmail = true` then this check should already be performed for you - as per this page.
Problem
I am using the default ASP.NET MVC Membership Provider and I would like to allow user's to modify their email after they have created their account. I do not want users to be able to use a duplicate email. How do I allow a user to modify their email and check that the email is not in use elsewhere in the database? I am not sure of the best way to do this type of check when using the default Membership Provider. note - I know the Membership Provider itself performs this check when a user attempts to register their email address, I do not know how to perform this check at a later time (due to noobness). note 2 - I only know of this method of accessing the user's email, is this the proper way to be accessing it? ``` MembershipUser useremail = Membership.GetUser(User.Identity.Name); ViewBag.Email = useremail.Email; ```