Issue with username validation message in asp.net identity

前端 未结 2 903
太阳男子
太阳男子 2020-12-18 00:08

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

相关标签:
2条回答
  • 2020-12-18 00:39

    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.

    0 讨论(0)
  • 2020-12-18 00:45

    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);
        }
    }
    
    0 讨论(0)
提交回复
热议问题