Open Closed

Issue After Many Locations and User Organization mapping #9941


User avatar
0
viswajwalith created

We are facing the issue during login process. when we have number of locations "AbpUserOrganizationUnits" (we have around 1500 Locations) and all of he locations is mapped to the users "AbpUserOrganizationUnits", The number of users are around 3000 this was working ok in our previous ABP 5 solution but after upgrading to Abp9 we found lot time it is taking top process the below code, around 3 minutes hence getting the timeout as well

In order top check this We have created a simple layered solution, and loaded with 2000 Locations. in this case we observed lo of time is taking at

As per our analysis we are suspecting on claims. This is very critial and makor concern.


3 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent

    You are experiencing severe performance issues during login when users are mapped to a large number of organization units (e.g., 1500+ per user, 3000 users total) after upgrading to ABP 9.0. This is a known challenge when the claims principal is populated with a very large number of organization unit claims, as each claim is loaded and processed during authentication.

    Solution & Recommendations

    1. Claims Optimization:

      • By default, ABP adds all organization unit IDs as claims to the user during login. With thousands of claims, this can cause significant performance degradation.
      • You should avoid loading all organization unit claims into the user's principal if not strictly necessary for every request.
    2. Recommended Approaches:

      • Reduce Claims Count: Only add essential claims to the principal. If you only need to check organization membership occasionally, consider querying the database or using a cache instead of claims.
      • Custom Claims Principal Factory: Override the IUserClaimsPrincipalFactory to limit or filter the organization unit claims added to the principal.
      • Use Data Filters: For data access, use ABP's data filtering and permission system instead of relying on claims for every organization unit.
      • Paging or Caching: If you must check many organization units, implement paging or caching strategies outside the claims system.
    3. Reference Implementation:

    4. Example: Custom Claims Principal Factory

    public class MyUserClaimsPrincipalFactory : AbpUserClaimsPrincipalFactory
       {
           public MyUserClaimsPrincipalFactory(
               UserManager<IdentityUser> userManager,
               RoleManager<IdentityRole> roleManager,
               IOptions<IdentityOptions> optionsAccessor)
               : base(userManager, roleManager, optionsAccessor)
           {
           }
    
           protected override async Task AddOrganizationUnitsAsync(IdentityUser user, ClaimsIdentity identity)
           {
               // Only add a limited number of OUs, or none, or a summary claim
               // Example: Add only the first 10 OUs
               var organizationUnits = await UserManager.GetOrganizationUnitsAsync(user);
               foreach (var ou in organizationUnits.Take(10))
               {
                   identity.AddClaim(new Claim(AbpOrganizationUnitClaimType, ou.Id.ToString()));
               }
           }
       }
    
    • Register your custom factory in DI.
    1. ABP 9.x Changes:
      • ABP 9 introduced some changes in claims and dynamic claims handling. If you have custom logic, review the upgrade notes and ensure your customizations are compatible.

    Summary

    • Do not add thousands of claims to the user principal.
    • Use custom claims principal logic to limit claims.
    • Use ABP's data filtering and permission system for organization unit checks.
    • Review and optimize your login and claims logic for large-scale organization unit scenarios.

    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
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share your test project?

    liming.ma@volosoft.com

    Thanks.

  • User Avatar
    0
    viswajwalith created

    [maliming] said: hi

    Can you share your test project?

    liming.ma@volosoft.com

    Thanks.

    Hi, You can give a try by creating a sample layered solution and creating the Locations

    I emailed the script...

    Let me know in case of any queries....

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 23, 2025, 10:47