Change the ASP.NET Identity messages
Asked Answered
T

1

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);
        }
    }
Tavares answered 13/1, 2014 at 10:15 Comment(4)
Please show relevant code and point out what exactly you want to change.Diuresis
As of current version just replace messages at display. Next version has a feature. Look this : How to localize error messages? #19962148Jola
@Diuresis I've updated, please see it, thanks.Tavares
you can localize error messages v2 identity https://mcmap.net/q/235004/-how-to-localize-asp-net-identity-username-and-password-error-messagesSenter
S
-2

possible duplicate https://mcmap.net/q/235004/-how-to-localize-asp-net-identity-username-and-password-error-messages

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>
Senter answered 22/3, 2014 at 5:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.