Open Closed

Set Tenant automatically based on host name #327


User avatar
0
hraval created

Hi,

I am looking for solution to set Tenant automatically based on the current host url. I reviewed the availale documents of abp but couldn't found any way for this.

Please share insight on this.

Thanks


6 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi

    Please see https://docs.abp.io/en/abp/latest/Multi-Tenancy#domain-tenant-resolver.

  • User Avatar
    0
    hraval created

    Hi,

    I reviewed the article but i don't know how to make it work with angular.

    Let say I login with admin and create tenant named "localhost:4201" and then re run the angular app with 4201 port. Then it should default load the "localhost:4201" tenant.

    I tried set "localhost:4201" directly in domain resolver code(for testing only) as follows but it didn't worked.

                Configure<AbpTenantResolveOptions>(options =>
                {
                    options.TenantResolvers.Insert(1, new DomainTenantResolveContributor("http://localhost:4201/"));
                });
    

    Please help me understand the flow here.

    Thanks.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    For example:

    Your application ur is http://localhost:4200, you want http://tenant1.localhost:4200 to be tenant1.

    Config should be :

     Configure<AbpTenantResolveOptions>(options =>
    {
        options.TenantResolvers.Insert(1, new DomainTenantResolveContributor("{0}.localhost"));
    });
    

    About multi-tenancy for Angular UI, you can refer https://github.com/abpframework/abp/blob/dev/docs/en/UI/Angular/Multi-Tenancy.md

  • User Avatar
    0
    ninomartini created

    Abp v3.04/MongoDb/Angular

    I am trying to implement this without success. In the HttpApi.Host project I modify ConfigServices to include the domain resolver.

    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        var configuration = context.Services.GetConfiguration();
        var hostingEnvironment = context.Services.GetHostingEnvironment();
    
        Configure<AbpTenantResolveOptions>(options =>
        {
            options.TenantResolvers.Insert(1, new DomainTenantResolveContributor("{0}.localhost"));
        });
    
        ConfigureUrls(configuration);
        ConfigureConventionalControllers();
        ConfigureAuthentication(context, configuration);
        ConfigureSwagger(context);
        ConfigureLocalization();
        ConfigureVirtualFileSystem(context);
        ConfigureCors(context, configuration);
    }
    

    In my Angular project I update the enviroment.ts file to inlciude a baseUrl.

    export const environment = {
      production: false,
      application: {
        baseUrl: 'https://{0}.localhost/',
        name: 'Mmg',
      },
      oAuthConfig: {
        issuer: 'https://localhost:44383',
        clientId: 'Mmg_App',
        dummyClientSecret: '1q2w3e*',
        scope: 'Mmg',
        showDebugInformation: true,
        oidc: false,
        requireHttps: true,
      },
      apis: {
        default: {
          url: 'https://localhost:44383'
        },
      },
      localization: {
        defaultResourceName: 'Mmg',
      }
    };
    

    http://localhost:4200/ will launch the application successfully. http://demo.localhost:4200/ returns status code 304 with a response of Invalid Host Header. Can you help shed some light on what I missed?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Sorry, I mean your HTTP API application url. About multi-tenancy for Angular UI, you can refer https://github.com/abpframework/abp/blob/dev/docs/en/UI/Angular/Multi-Tenancy.md

  • User Avatar
    0
    alper created
    Support Team Director

    closed due to inactivity...

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11