Overriding the Identity Error Messages


AFAIK, currently the error messages in identity library are not override-able. For example, we cannot override 'Name {0} is already taken.'. This will cause a big headache for multi-lingual application and also in some other cases, http://forums.asp.net/t/1957899.aspx?How+to+override+validation+for+UserName


pcalsavara wrote Jan 10, 2014 at 4:19 PM

The content of Microsoft.AspNet.Identity.Resources is:

UserAlreadyInRole=User already in role.UserNotInRole=User is not in role.RoleNotFound=Role {0} does not exist.StoreNotIUserClaimStore=Store does not implement IUserClaimStore.PasswordMismatch=Incorrect password.StoreNotIUserRoleStore=Store does not implement IUserRoleStore.StoreNotIUserLoginStore=Store does not implement IUserLoginStore.InvalidUserName=User name {0} is invalid, can only contain letters or digits.PasswordTooShort=Passwords must be at least {0} characters.DuplicateName=Name {0} is already taken.UserAlreadyHasPassword=User already has a password set.StoreNotIUserPasswordStore=Store does not implement IUserPasswordStore.UserIdNotFound=UserId not found.UserNameNotFound=User {0} does not exist.NameTooShort=Name cannot be null or empty.StoreNotIUserSecurityStampStore=Store does not implement IUserSecurityStampStore.ExternalLoginExists=A user with that external login already exists.DefaultError=An unknown failure has occured.

I´ve tried to change the Messages.resx with some of these values, but has no effect.

1AmirJalali wrote Mar 17, 2014 at 6:10 PM

It also would be helpful to show an example of how to check for available username through ajax

HaoK wrote Sep 2, 2014 at 7:56 PM

We are looking at this for v3

** Closed by HaoK 09/02/2014 11:56AM

mattjenkins wrote Oct 23, 2014 at 4:21 PM

Any chance of an update on this? It's a fairly important requirement, as evidenced by the number of votes already raised before the issue was closed.

mahdika wrote Jan 7, 2015 at 1:34 PM

Why such an important issue has been closed? What has been the result?

SaiiLlcEcommerce wrote May 19, 2015 at 1:21 AM

The hard coding of messages was a poor choice.

divega wrote May 22, 2015 at 10:41 PM

We are re-activating this for 2.x since there seems to be a lot of interest and it looks like the implementation we did in 3.0 (minus the reliance on dependency injection) could be back ported to 2.x. This item is "up for grabs", meaning that we believe it would be a good work item for a contributor outside of the ASP.NET Identity team to work on.

SaiiLlcEcommerce wrote May 30, 2015 at 5:17 PM

Microsoft Team,

Please review the post http://aspnetidentity.codeplex.com/discussions/638351. This identifies other ASP.NET Identity localization obstacles including;

1) need for specific culture (Satellite Assemblies) rather than neutral culture (Main Assemblies) localization
2) hard coded codebase strings
3) regular expressions
4) client side error messages (JavaScript)
5) data annotation limitations
6) concatenated error message

Thanks Everyone, Dave from Redding, CA

DonaldF wrote Sep 19, 2016 at 9:45 AM

The smart and easy option would be to make the strong typed Resources class public with a public settable ResourceManager property so that one, should they so choose, can set their own local Resource manager.
This is what I have done in code to achieve this (via reflection hacking).
            var ass = Assembly.Load("Microsoft.AspNet.Identity.Core, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
            //Type hack = test.GetType()
            Type hack = ass.GetType("Microsoft.AspNet.Identity.Resources");
            var field = hack.GetField("resourceMan",
                            BindingFlags.Static |
            //This is where you set your own local resource manager that will read resource files from your own assembly
            field.SetValue(null, new global::System.Resources.ResourceManager("WebApplication1.Resources", typeof(WebApplication1.Resources).Assembly));
In the above code my application name/namespace was labeled WebApplication1.
In the "ideal" World I would not need to use reflection to set the resource manager. This in my opinion is the cleanest solution. You could even make a "wrapper" resource manger that looked for you local resources first, if it didn't find them, resort to using the original resources.