Base solution for your next web application
Open Closed

login which navigating to client application does not work with the tenant specific url #10933


User avatar
0
shedspotter created

What is your product version? 11.0.0

What is your product type (Angular or MVC)? Angular

What is product framework type (.net framework or .net core)? .NET 6

Hi in the highlighted section, in web site it is mention that it will navigates you to front end application, does it work with sub domains as well becuase I have tried to copy the logic of the login form web.public > HeaderViewComponent and added the another conteroller in web.host and pasted the logic there. I have to do that becuase I do not want another service to be publish. After coping the logic it is working fine If there is not sub domain i.e it working fine with tenant switcher but when I am enabling the sub domain and instad of url I am using tenant url ,it is not working, Could you please help us on this issue.

Note : Sub domain = tenant specfic URL

code which I have copied and modifed and we have added the login button in on the public web site in which we are using super admin api end point to for checking the tenantId, but every time we are getting null. Please provide a solution asap.

        var tenancyName = "";
        var customDomin = "";
        if (_abpSession.TenantId.HasValue)
        {
            var tenant = await _tenantManager.GetByIdAsync(_abpSession.GetTenantId());
            tenancyName = tenant.TenancyName;
            customDomin = tenant.CustomDomain;
        }


        var headerModel = new HeaderViewModel();

        headerModel.LoginInformations = await _sessionCache.GetCurrentLoginInformationsAsync();
        headerModel.IsInHostView = !_abpSession.TenantId.HasValue;
        headerModel.Languages = _languageManager.GetActiveLanguages().ToList();
        headerModel.CurrentLanguage = _languageManager.CurrentLanguage;
        headerModel.CurrentPageName = "Home";
        headerModel.IsMultiTenancyEnabled = _multiTenancyConfig.IsEnabled;
        headerModel.TenantRegistrationEnabled = await _settingManager.GetSettingValueAsync<bool>(AppSettings.TenantManagement.AllowSelfRegistration);
        headerModel.AdminWebSiteRootAddress = _webUrlService.GetServerRootAddress(tenancyName).EnsureEndsWith('/');
        headerModel.WebSiteRootAddress = string.IsNullOrWhiteSpace(customDomin) ? _webUrlService.GetSiteRootAddress(tenancyName).EnsureEndsWith('/') : $"https://{customDomin}/";
        if (headerModel.LoginInformations.Tenant == null)
        {
            return View("NewUser");
        }
        return View(headerModel);

please let me know what endpoint should I use, in which user navigate and it will pick the tenancy of that user where user is using tenant specifc url ? Thanks


7 Answer(s)
  • User Avatar
    0
    musa.demir created

    Hi @shedspotter

    Here is how aspnetzero revolves tenant id from url in mvc applications: https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.AspNetCore/AspNetCore/MultiTenancy/DomainTenantResolveContributor.cs

    Can you please check if implementing it solves your problem.

  • User Avatar
    0
    shedspotter created

    Hi musa.demir, it is resolving the tenant id corrctly but the problem over there is we are using super admin api endpoint for executing the above code, but becuase we have multitenancy has been enable and we are using tenancy name as subdomain in that case it is always pic tenant id as null. For example :suppose a user has been logged in our website and closed the browser. Now he will back and want navigate to our application. so what he does he will go to the our public web site and over there he will click on login button. now the issues occure over there .

    1. we are using super admin api endpoint i.e http://host.api.abc.in becuase we have multitenancy enable so it will pic tenant id as null from abp session becuase host user does not have any tenant
    2. if we are using the user api endpoint for executing the above methods i.e http://xyz.api.in then it will pic the tenant id of xyz tenant from abp session but we can not us this because we can not set navigation endpoint like this.

    so please let me know how can we fixed this and plese let me know the login button functioanlity in public web site is working with tenant specific url or not

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @shedspotter

    Do you use subdomains as tenants both for public and admin websites ?

  • User Avatar
    0
    shedspotter created

    Hi @ismcagdas , no we are only using subdomains for admin websites

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    So, how can you determine the tenant on the public website ? If you can't determine the tenant on the public website, you can't redirect user to correct URL on the admin side.

  • User Avatar
    0
    shedspotter created

    Hi @ismcagdas, That's the question we have that how can we achive that when we are using sub domains

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @shedspotter

    If you are not using subdomains for your public website and still want to get current visitor's TenantId, then you can show a dialog to to user and ask user to enter tenancy name. Then, you can store it in the browser's local storage. When user visits the website next time, you can skip showing the tenancy selection.

    Also, it will be good to show currently selected tenant on the public website (top right corner maybe as a link) and when this tenancy name is clicked, allow user to set another tenancy name using the same modal.