8

I am using new membership system asp.net identity in my project. I want to use Email address as an Username and yes i have looked these questions already:

Configure Microsoft.AspNet.Identity to allow email address as username

ASP.NET identity use email instead of user name

and i know how to use email as a Username.But i have another issue, the Validation error message:

Name [email protected] is already taken.

this message comes when user try to register with existing email address.So instead of this error message i want to give error message some like:

User with the given email address already exist.

So how can i do this in Asp.Net identity ??

2 Answers 2

11

Its just replacing the message. Search for the "Name {0} is already taken." and replace it with your message "User with the given email address already exists".

You can do it in AddError method. This is an example, you shall create application specific working code.

private void AddErrors(IdentityResult result)
{
    foreach (var error in result.Errors)
    {
        if (error.EndsWith("is already taken."))
            ModelState.AddModelError("", "User with the given email address already exists");
        else ModelState.AddModelError("", error);
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

This works but it's not elegant. I believe the ASP.NET Identity team is working on the real code - source here: stackoverflow.com/a/19962202/687549
2

Another option would be to plug in your own UserValidator that only does the user name/email check, if it doesn't fail, it delegates to the default UserValidator, otherwise it returns an IdentityResult with the error message you want.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.