Base solution for your next web application
Open Closed

Angular does not add Abp.TenantId cookie #4783


User avatar
0
trenxo created

Hi guys,

I deployed ASP.NET Core + Angular to 2 Azure web app services.

They seem to work ok but I always get to the host dashboard because the Abp.TenantId cookie is never set. I think it should be set from the subdomain in AppPreBootstrap class.

Any ideas?

My configs:

Angular appconfig.json:

"remoteServiceBaseUrl": "http://myapi.azurewebsites.net/",
"appBaseUrl": "http://{TENANCY_NAME}.mydomain.com/"

Web.Host appsettings.Production.json:

"ServerRootAddress": "http://myapi.azurewebsites.net/",
"ClientRootAddress": "http://{TENANCY_NAME}.mydomain.com/"

5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    @trenxo, when you are using subdomains, you shouldn't need tenantId on the cookie because the requests must be made to http://{TENANCY_NAME}.mydomain.com/, for example <a class="postlink" href="http://default.mydomain.com/">http://default.mydomain.com/</a>, so tenantId will be found on the server.

    Can you check if the requests are made to correct url ?

  • User Avatar
    0
    ubiquo created

    Hi @ismcagdas, I'm having this same issue. Because of this I'm not able to log in into any tenant, only the host. I also have {TENANCY_NAME} in remoteSeriveBaseUrl and ServerRootAddress.

    "remoteServiceBaseUrl": "http://{TENANCY_NAME}.mydomain.com/Host",
    "appBaseUrl": "http://{TENANCY_NAME}.mydomain.com/Angular"
    
    "ServerRootAddress": "http://{TENANCY_NAME}.mydomain.com/Host",
    "ClientRootAddress": "http://{TENANCY_NAME}.mydomain.com/Angular"
    

    I tried on my local machine following the steps in here [https://github.com/aspnetzero/aspnet-zero-core/issues/557])

  • User Avatar
    0
    alper created
    Support Team

    hi,

    in subdomain setup there's no Abp.TenantId in the cookies. see the AspNetZero online demo website (it's Angular too) [attachment=0:6qe7h60d]angular-token.jpg[/attachment:6qe7h60d]

    Maybe the URL scheme is the problem. If you are using SSL try HTTPS in the template URLs.

    "remoteServiceBaseUrl": "https://{TENANCY_NAME}.mydomain.com/Host",
    "appBaseUrl": "https://{TENANCY_NAME}.mydomain.com/Angular"
    

  • User Avatar
    0
    ubiquo created

    You are right, in the demo site there is no Abp.TenantId, but I noticed that when calling GetCurrentLoginInformations it is not returning the tenant info. Is there any configuration that I'm missing?

    Left -> demo site, Right -> my site.

    if (AbpSession.TenantId.HasValue)
    {
        output.Tenant = ObjectMapper
            .Map<TenantLoginInfoDto>(await TenantManager
                .Tenants
                .Include(t => t.Edition)
                .FirstAsync(t => t.Id == AbpSession.GetTenantId()));
    }
    

    Apparently AbpSession.TenantId has no value.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @biquo,

    There might be some other reasons for this.

    1. If you are running your app on nginx, the request header might be removed. Can you see the Abp.TenantId request header value on your browser's network tab ?

    2. If you are using Internet Explorer, it might cause such problems for older versions of AspNet Zero.

    Can you also share your abp-ng2-module version, ABP nuget package version and AspNet Zero version ?

    Thanks.