Cli command:
abp new Acme.BookStore -t app-pro -u angular
Access login connect/token
Shell command:
curl --location --request POST 'http://localhost:44372/connect/token' \
--header 'Accept-Language: zh-Hans' \
--header '__tenant: demo' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Host: localhost:44372' \
--header 'Connection: keep-alive' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'client_id=BookStore_App' \
--data-urlencode 'scope=BookStore' \
--data-urlencode 'username=admin' \
--data-urlencode 'password=1q2w3E*'
Exception reponse content:
<html lang="zh-Hans">
<head>
<meta charset="utf-8" />
<title>&#x672A;&#x627E;&#x5230;&#x79DF;&#x6237;&#xFF01;</title>
</head>
<body>
<h3>&#x672A;&#x627E;&#x5230;&#x79DF;&#x6237;&#xFF01;</h3>
<p>&#x6CA1;&#x6709;&#x79DF;&#x6237;&#x7684; ID
&#x6216;&#x540D;&#x79F0;&#x4E3A;&#xFF1A;demo&#x7684;&#x79DF;&#x6237;&#x3002;
<p />
</body>
</html>
It has been discovered that this issue only applies to 'Accept-Language: zh-Hans'
.
This is a normal response request.:
curl --location --request POST 'http://localhost:44372/connect/token' \
--header 'Accept-Language: en' \
--header '__tenant: demo' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Host: localhost:44372' \
--header 'Connection: keep-alive' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'client_id=BookStore_App' \
--data-urlencode 'scope=BookStore' \
--data-urlencode 'username=admin' \
--data-urlencode 'password=1q2w3E*'
Reponse content:
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Tenant not found!</title>
</head>
<body>
<h3>Tenant not found!</h3>
<p>There is no tenant with the tenant id or name: demo
<p />
</body>
</html>
The commercial and the community are different.
Community version response content:
{
"error": {
"code": "Volo.AbpIo.MultiTenancy:010001",
"message": "An internal error occurred during your request!",
"details": null,
"data": {},
"validationErrors": null
}
}
I think the response content of the community is correct.
How to temporarily fix the problem of character encoding errors in the commercial ? How can my response content be adjusted to be the same as that of the community?
5 Answer(s)
-
0
To address the garbled character issue and unify the error response format for invalid tenants in your ABP commercial application, you should adjust the way tenant-not-found errors are handled and returned by your backend.
Problem Analysis
- The commercial version returns an HTML error page with encoded characters for non-English languages (e.g., zh-Hans), while the community version returns a JSON error object.
- This difference is due to the built-in error handling pipeline in the commercial edition, which by default returns an HTML error page for certain errors, especially when localization is involved.
Solution Steps
1. Force JSON Error Responses for API Endpoints
You can globally configure your API to always return JSON error responses (like the community version) by customizing the exception handling middleware. In your
Startup
or module configuration, add the following:public override void ConfigureServices(ServiceConfigurationContext context) { Configure<AbpExceptionHandlingOptions>(options => { options.SendExceptionsDetailsToClients = true; options.ExceptionHandlingPath = "/api/error"; // Ensure this path returns JSON }); }
2. Add a Custom Exception Filter (Optional)
If you want to ensure all errors (including tenant not found) are returned as JSON, you can add a global exception filter:
public class JsonExceptionFilter : IExceptionFilter { public void OnException(ExceptionContext context) { context.Result = new JsonResult(new { error = new { code = "Volo.AbpIo.MultiTenancy:010001", message = context.Exception.Message } }) { StatusCode = StatusCodes.Status400BadRequest }; context.ExceptionHandled = true; } } // Register in ConfigureServices context.Services.Configure<MvcOptions>(options => { options.Filters.Add<JsonExceptionFilter>(); });
3. Ensure API Controllers Use
[ApiController]
Make sure your API controllers are decorated with
[ApiController]
to enforce content negotiation and JSON responses.4. Check Localization Files
If you want to customize the error message, update your localization files for the relevant language (e.g., zh-Hans) to ensure proper translation and encoding.
5. Temporary Workaround
If you need a quick fix, you can set the
Accept
header toapplication/json
in your client requests to force the backend to return JSON:--header 'Accept: application/json'
Summary
- Configure exception handling to always return JSON for API endpoints.
- Optionally, add a global exception filter for consistent error formatting.
- Use the
Accept: application/json
header as a temporary workaround.
This will make your commercial edition's error responses consistent with the community edition and resolve the character encoding issue.
Sources:
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
The reply from the AI-Bot cannot solve the issue.
-
0
hi
I will check this.
Thanks.
-
0
-
0
https://github.com/abpframework/abp/pull/23463