Open Closed

The invalid tenant response content is presented in garbled form. #9742


User avatar
0
464199480 created

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>&amp;#x672A;&amp;#x627E;&amp;#x5230;&amp;#x79DF;&amp;#x6237;&amp;#xFF01;</title>
</head>

<body>
    <h3>&amp;#x672A;&amp;#x627E;&amp;#x5230;&amp;#x79DF;&amp;#x6237;&amp;#xFF01;</h3>
    <p>&amp;#x6CA1;&amp;#x6709;&amp;#x79DF;&amp;#x6237;&amp;#x7684; ID
        &amp;#x6216;&amp;#x540D;&amp;#x79F0;&amp;#x4E3A;&amp;#xFF1A;demo&amp;#x7684;&amp;#x79DF;&amp;#x6237;&amp;#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)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent

    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 to application/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.

  • User Avatar
    0
    464199480 created

    The reply from the AI-Bot cannot solve the issue.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I will check this.

    Thanks.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    I will fix it in the next 9.3 patch version.

    You can customize the MultiTenancyMiddlewareErrorPageBuilder to resolve this issue now.

    https://abp.io/docs/latest/framework/architecture/multi-tenancy#abpaspnetcoremultitenancyoptions

    Thanks.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    https://github.com/abpframework/abp/pull/23463

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.0.0-preview. Updated on September 04, 2025, 08:36