Open Closed

Invalid username message not displayed #9037


User avatar
0
geoff.hardy created

When attempting to save a new user with an invalid username (for example, a username with spaces), the POST users endpoint does not return a useful error message.

For example, this username is invalid due to spaces:

After pressing the Save button, the user gets an "Unknown failure has occurred" message, which is not very user friendly:

This problem appears to have been introduced when resolving this issue:

https://abp.io/support/questions/8215/Identity-module-error-handling

AbpIdentityResultExtensions.GetValuesFromError message does not find the correct error message, because the IdentityStrings values were changes in the AbpIdentityResultExtensions static constructor:

        if (IdentityStrings.ContainsKey("InvalidUserName"))
        {
            IdentityStrings["InvalidUserName"] = "Username '{0}' is invalid.";
        }

To reverse this problem, I had to do the following at the start of the Host Program:

    private static void FixIdentityResources()
    {
        var identityStrings = (typeof(AbpIdentityResultExtensions)
            .GetField("IdentityStrings", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance)
            ?.GetValue(null) ?? new Dictionary<string, string>()).As<Dictionary<string, string>>();
        // Fix the resource strings used by AbpIdentityResultExtensions, which are changed in the AbpIdentityResultExtensions static constructor
        if (identityStrings.ContainsKey("InvalidUserName"))
        {
            identityStrings["InvalidUserName"] = "Username '{0}' is invalid, can only contain letters or digits.";
        }
    }

This results in the correct error message being displayed:

Having to do this hack is not ideal.

Is there a better way to resolve this? Or is this problem likely to be fixed in a future release of ABP?

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Thanks. I wll check and fix this problem. 👍

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Your ticket has been refunded.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I have checked. >=9.0.5 will fix the problem, see https://github.com/abpframework/abp/pull/22137

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
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.8.0-preview. Updated on October 05, 2026, 11:32
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.