Base solution for your next web application
Open Closed

Set Tenant based on url #3562


User avatar
0
walkerscott created

Hi,

How can I set the tenant based on URL?

Scenario is an email is sent to the users with the URL to access specific page. The URL has an identifier that can let us know what tenant the URL is for. In our case GUID.

What we want is upon accessing the URL, if not logged in, it will set the Tenant on TenancyName on Login Page. So that the page will not lose the return URL as well.

I was able to set the Tenant but I can't write the cookie for Abp.TenantId. I write it on SessionAppService.GetCurrentLoginInformations(), but can't write the cookie from it.

My code for writing the cookie is below..

_httpContextAccessor.HttpContext.Response.Cookies.Append(
                    "Abp.TenantId",
                    userUrlTenantId.ToString(),
                    new CookieOptions
                    {
                        Expires = DateTimeOffset.Now.AddYears(5),
                        Path = "/"
                    }
                );

2 Answer(s)
  • User Avatar
    0
    walkerscott created

    Okay I got it already.. So i found the app-session.service.ts, and I set the cookie from there.

    abp.multiTenancy.setTenantIdCookie(result.tenant.id);
    
  • User Avatar
    0
    alper created
    Support Team

    good to hear it works