How to change error message in ASP.NET Identity

后端 未结 2 990
梦毁少年i
梦毁少年i 2021-02-13 13:24

I have one question. I\'m trying change error message in Identity ASP .NET and I don\'t know how do it. I want change error message - \"Login is already taken\". CreateAsync m

2条回答
  •  無奈伤痛
    2021-02-13 13:53

    private void AddErrors(IdentityResult result)
    {
        foreach (var error in result.Errors)
        {
            if (error.StartsWith("Name"))
            {
                var NameToEmail= Regex.Replace(error,"Name","Email");
                ModelState.AddModelError("", NameToEmail);
            }
            else
            {
                ModelState.AddModelError("", error);
            }
        }
    }
    

提交回复
热议问题