8

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);
        }
    }
Saeed Hamed
  • 732
  • 2
  • 10
  • 28
  • 2
    Please show relevant code and point out what exactly you want to change. – CodeCaster Jan 13 '14 at 10:33
  • 2
    As of current version just replace messages at display. Next version has a feature. Look this : How to localize error messages? http://stackoverflow.com/questions/19961648/how-to-localize-error-messages/19962202#19962202 – jd4u Jan 13 '14 at 11:33
  • @CodeCaster I've updated, please see it, thanks. – Saeed Hamed Jan 14 '14 at 03:46
  • you can localize error messages v2 identity http://stackoverflow.com/a/22573802/1037267 – Amir Jalali Mar 22 '14 at 05:23

1 Answers1

-2

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>
Community
  • 1
  • 1
Amir Jalali
  • 3,132
  • 4
  • 33
  • 46