Change the ASP.NET Identity messages

Saeed Hamed picture Saeed Hamed · Jan 13, 2014 · Viewed 10k times · Source

I'm using ASP.NET Identity as membership system in my project. After creating a user I want to check the result and I return the original IdentityResult errors. How can I change these messages?

Thanks.

Update:

 public virtual async Task<ActionResult> Register(RegisterViewModel model)
 {
        if (ModelState.IsValid)
        {
            var user = new ApplicationUser() { UserName = model.UserName };
            var result = await UserManager.CreateAsync(user, model.Password);
            if (result.Succeeded)
            {
                FormsAuthentication.SetAuthCookie(user.UserName, false);
                return RedirectToAction("Index", "Home");
            }
            else
            {
                AddErrors(result);
            }
        }

        return View(model);
    }

    private void AddErrors(IdentityResult result)
    {
        foreach (var error in result.Errors)
        {
            //I need to change error text message here!
            ModelState.AddModelError("", error);
        }
    }

Answer

Amir Jalali picture Amir Jalali · Mar 22, 2014

possible duplicate https://stackoverflow.com/a/22573802/1037267

you can now localize error messages

As of version 2 of identity which released on 20 march 2014 you can now have localized error messages.

The proper culture must be set in order to get localized messages for example one way to set culture is in web.config

<system.web>
     <globalization culture="fr-FR" uiCulture="fr"/>
</system.web>