Open Closed

Access to Current Tenant in Menu Contributors #9087


User avatar
0
shodgson created

Hello,

i'm currently trying to get the CurrentTenant information within the context of a custom IMenuContributor. When the ConfigureMenuAsync executes on the server side the current tenant id is properly populated from the ICurrentTenant implementation but it is null when executing for web assembly. Here's my ConfigureMainMenuAsync from a custom IMenuContributor which is properly registered on the menu contributors

    private static async Task ConfigureMainMenuAsync(MenuConfigurationContext context)
    {
        var l = context.GetLocalizer();

        var currentTenant = context.ServiceProvider.GetRequiredService<ICurrentTenant>();        

        // Prints the current tenant id/name on the server
        // Prints null on web assembly
        Console.WriteLine($"Current tenant is {currentTenant.Id}: {currentTenant.Name}");

        if (currentTenant.Id == null)
        {
            // Custom logic for the Host
        }
    }

Any ideas why that is?

Thanks !!


4 Answer(s)
  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hi,

    I created a Blazor Web App project from scratch to reproduce your problem.

    This application uses ABP packages with version 9.1.0.

    I added the code you mentioned as in the picture but I could not reproduce the problem:

    Screenshot 2025-04-07 at 14.42.40.png

    Result:

    Screenshot 2025-04-07 at 14.42.21.png

    Can you create a project from scratch and try to reproduce this situation to make sure that the problem belongs to your case? If you can reproduce the problem in a project created from scratch, let me know the version of the project you created, etc. and I will try.

  • User Avatar
    0
    shodgson created

    Thanks for the response.

    Unfortunately it seems I can reproduce the issue even on a new microservice solution.

    I'm on version 9.1

    Steps to reproduce on my side:

    • Create a new microservice solution from the abp studio

    • EF Core database provider

    • Multitenancy enabled

    • Blazor WebApp as the UI framework

    • No mobile framework

    • No public website

    • No dynamic localization

    • OpenIddict UI enabled

    • LeptonX theme

    • Add this block in the .Client assembly in the MenuContributor file

     var currentTenant = context.ServiceProvider.GetRequiredService();
    
     Console.WriteLine($"Running on the browser: {OperatingSystem.IsBrowser()} Current tenant is {currentTenant.Id}: {currentTenant.Name}");
    
    • Run the solution and create a tenant

    • Login on that new tenant and notice the empty tenantid/tenantname in the console

    • Screenshot 2025-04-08 092244.png

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hi,

    Thanks to the information you provided, I was able to reproduce the problem. The problem does not occur in the Application Layered template, but in the Microservice solution, so I could not reproduce it the first time. I will create an internal issue, and we will keep you informed about the progress. Thank you for your patience.

  • User Avatar
    0
    shodgson created

    Hi,

    Thanks to the information you provided, I was able to reproduce the problem. The problem does not occur in the Application Layered template, but in the Microservice solution, so I could not reproduce it the first time. I will create an internal issue, and we will keep you informed about the progress. Thank you for your patience.

    Thank you,

    I'll wait for an issue link to track the progress

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on April 09, 2025, 10:18