Hello , I have a custom validation on creating User so I Used IUserValidator<IdentityUser> but I get message not localized correctly although it exists in my localization files with key :"Volo.Abp.Identity:PhoneNumberStartsWithZero" Here is the validate function
- ABP Framework version: v5.1
- UI type: MVC
- DB provider: EF Core
3 Answer(s)
-
0
Hi,
Could you provide the full steps to reproduce? thanks.
-
0
Hello , Here is the steps: 1- Add the custom validator in domain layer and its configurations 2- try to add new user from from administration (his phone number start with 0), but instead of getting phone number... msg ,it gets me "identity.Default"
here is the sample of a validation action called in validateAsync==>
-
0
Hi,
ABP is designed to be compatible with ASP.NET Core Identity and will try to localize error code, but it doesn't support custom errors.
The solution is very simple, you just need to throw a
BusinessException
:public const string PhoneNumberStartsWithZeroError = "MyProjectName:PhoneNumberStartsWithZero"; public Task<IdentityResult> ValidateAsync(UserManager<IdentityUser> manager, IdentityUser user) { throw new BusinessException(PhoneNumberStartsWithZeroError); } Configure<AbpExceptionLocalizationOptions>(options => { options.MapCodeNamespace("MyProjectName", typeof(MyProjectNameResource)); });