2 Answer(s)
-
0
- Solution
- ABP localizes exception messages by mapping exception “code namespaces” to a localization resource. Configure this once and all infrastructure errors that have codes (like authorization/validation) will be shown in the current UI culture.
- Add a resource for your app (Domain.Shared) and map the ABP namespaces that you want to localize.
Example: Map authorization/validation/identity namespaces to your resource and provide translations.
csharp // Domain.Shared module [DependsOn( typeof(AbpExceptionHandlingModule), typeof(AbpValidationModule), typeof(AbpAuthorizationModule), typeof(AbpIdentityDomainSharedModule) )] public class MyProjectDomainSharedModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { Configure<AbpLocalizationOptions>(options => { options.Resources .Add<MyProjectResource>("en") .AddVirtualJson("/Localization/MyProject"); });
Configure<AbpExceptionLocalizationOptions>(options => { // Map exception code namespaces to your resource options.MapCodeNamespace("Volo.Abp.Authorization", typeof(MyProjectResource)); options.MapCodeNamespace("Volo.Abp.Validation", typeof(MyProjectResource)); options.MapCodeNamespace("Volo.Abp.Identity", typeof(MyProjectResource)); // add more if needed }); }}
- Create localization JSON files that contain the exception texts for the mapped namespaces.
- Place under MyProject.Domain.Shared/Localization/MyProject/
- Example en.json and tr.json (Turkish). Include keys used by ABP’s infrastructure. For “Forbidden” (authorization), ABP uses well-known codes and messages; provide localized texts.
en.json { "culture": "en", "texts": { "Volo.Abp.Authorization:DefaultErrorMessage": "The user represented by the token is not allowed to perform the requested action.", "Volo.Abp.Authorization:Forbidden": "Forbidden" } }
tr.json { "culture": "tr", "texts": { "Volo.Abp.Authorization:DefaultErrorMessage": "Belirteçle temsil edilen kullanıcı bu işlemi yapmaya yetkili değil.", "Volo.Abp.Authorization:Forbidden": "Yasak" } }
Notes:
- The exact keys used by ABP for authorization exceptions are tied to the exception code namespace Volo.Abp.Authorization. After mapping, any ABP-generated authorization error (like forbidden) is localized via your resource. If a specific key is missing, ABP falls back to the default message; add keys you need.
- Ensure your MVC UI sets and switches CurrentUICulture (ABP does this via the language selector/cookie). Then the modal error message will automatically be shown in the current language.
Optional: Customize the displayed title/text shape for MVC UI
- ABP MVC shows RemoteServiceErrorInfo (ProblemDetails) in a modal. To override formatting, implement IExceptionToErrorInfoConverter or subscribe to AbpExceptionEvent to adjust message keys, but in most cases mapping and providing translations is sufficient.
- Sources
- https://abp.io/docs/latest/framework/fundamentals/exception-handling
- https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/AbpAuthorizationErrorCodes.cs
This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.
-
0
hi
Which HTTP request gets this error message?
Thanks.
