# General question about multi tenancy in Radzen

**URL:** <https://forum.radzen.com/t/general-question-about-multi-tenancy-in-radzen/20374>\
**Category:** Radzen.Blazor Components\
**Created:** [May 21, 2025, 9:20am UTC](https://forum.radzen.com/t/general-question-about-multi-tenancy-in-radzen/20374 "2025-05-21T09:20:54Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Murmelmann](https://forum.radzen.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@Murmelmann](https://forum.radzen.com/u/Murmelmann)\
**Post date:** [May 21, 2025, 9:20am UTC](https://forum.radzen.com/t/general-question-about-multi-tenancy-in-radzen/20374/1 "2025-05-21T09:20:54Z")

</div>

This may be a very basic question but I am a bit confused by the docs about multi tenancy.

So assume I have a blazor web app running on [www.myapp.com](http://www.myapp.com)

This app has many clients each with many users.

So each client is basically a tenant, right?

But in order to create a tenant I need to add host information, but in this case doesn't every tenant use the same host [www.myapp.com](http://www.myapp.com)?

Or do I need to add subdomain for each client like [client1.myapp.com](http://client1.myapp.com)?

Maybe this is not even strictly related to Radzen but any help would be very much appreciated.

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [May 21, 2025, 11:13am UTC](https://forum.radzen.com/t/general-question-about-multi-tenancy-in-radzen/20374/2 "2025-05-21T11:13:16Z")

</div>

There are different implementations of multi-tenancy, more details about our implementation can be found here:

> **[Multi-tenancy](https://www.radzen.com/blazor-studio/documentation/security/multi-tenancy/)**
>
> Radzen Blazor Studio multi-tenancy support in Blazor Applications

---

<div class="post-metadata">

**Author:** ![Murmelmann](https://forum.radzen.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@Murmelmann](https://forum.radzen.com/u/Murmelmann)\
**Post date:** [May 21, 2025, 12:28pm UTC](https://forum.radzen.com/t/general-question-about-multi-tenancy-in-radzen/20374/3 "2025-05-21T12:28:54Z")

</div>

Thanks. Let me rephrase the question: in your implementation - can multiple tenants have the same host? From the link you shared I think so, but confirmation would be nice. Thanks

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [May 21, 2025, 12:37pm UTC](https://forum.radzen.com/t/general-question-about-multi-tenancy-in-radzen/20374/4 "2025-05-21T12:37:06Z")

</div>

Indeed there is no such restriction.

---

<div class="post-metadata">

**Author:** ![Murmelmann](https://forum.radzen.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@Murmelmann](https://forum.radzen.com/u/Murmelmann)\
**Post date:** [May 21, 2025, 2:03pm UTC](https://forum.radzen.com/t/general-question-about-multi-tenancy-in-radzen/20374/5 "2025-05-21T14:03:00Z")

</div>

Okay so I created two tenants. Tenant1 and Tenant2. Both have the same host "[myapp.com](http://myapp.com)". Each tenant has one user, user1 (tenant1) and user2 (tenant2).

When logging in I think this code is called:

```auto
        private ApplicationTenant GetTenant()
        {
            var tenants = Context.Set<ApplicationTenant>().ToList();

            var host = httpContextAccessor.HttpContext.Request.Host.Value;

            return tenants.Where(t => t.Hosts.Split(',').Where(h => h.Contains(host)).Any()).FirstOrDefault();
        }

```

So now when user2 wants to login, GetTenant() will always return tenant1 and user2 does not belong to tenant1 so logging in is not possible?

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [May 21, 2025, 2:27pm UTC](https://forum.radzen.com/t/general-question-about-multi-tenancy-in-radzen/20374/6 "2025-05-21T14:27:23Z")

</div>

Tenants and Users are created when logged with tenantsadmin - it's up to you what values you will assign. If you have same host for different user/tenant combination indeed this code will return the first tenant.

---

<div class="post-metadata">

**Author:** ![Murmelmann](https://forum.radzen.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@Murmelmann](https://forum.radzen.com/u/Murmelmann)\
**Post date:** [May 21, 2025, 2:29pm UTC](https://forum.radzen.com/t/general-question-about-multi-tenancy-in-radzen/20374/7 "2025-05-21T14:29:26Z")

</div>

Okay, but if I understand correctly this means that two tenants cannot have same host because in that case always the first tenant will be returned?

So basically I have to add a new subdomain for every tenant?

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [May 21, 2025, 2:31pm UTC](https://forum.radzen.com/t/general-question-about-multi-tenancy-in-radzen/20374/8 "2025-05-21T14:31:45Z")

</div>

> [@Murmelmann](#):
>
> So basically I have to add a new subdomain for every tenant?

Yes, that's the example in our documentation article I've referred.

---

<div class="post-metadata">

**Author:** ![Murmelmann](https://forum.radzen.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@Murmelmann](https://forum.radzen.com/u/Murmelmann)\
**Post date:** [May 21, 2025, 2:32pm UTC](https://forum.radzen.com/t/general-question-about-multi-tenancy-in-radzen/20374/9 "2025-05-21T14:32:33Z")

</div>

I think in your example here [Multi-tenancy | Radzen Blazor Studio](https://www.radzen.com/blazor-studio/documentation/security/multi-tenancy/)

tenant2user will not be able to login when navigating to localhost:5001 because tenant1 and tenant2 share the same host (localhost:5001) and therefore always tenant1 will be returned.

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [May 21, 2025, 2:47pm UTC](https://forum.radzen.com/t/general-question-about-multi-tenancy-in-radzen/20374/10 "2025-05-21T14:47:12Z")

</div>

When logged with tenantsadmin the tenant is switched manually:

 ![image](https://forum.radzen.com/uploads/default/original/3X/5/8/5873df91fd15e199091396252ada653450ef517f.png)

---

<div class="post-metadata">

**Author:** ![Murmelmann](https://forum.radzen.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@Murmelmann](https://forum.radzen.com/u/Murmelmann)\
**Post date:** [May 21, 2025, 2:50pm UTC](https://forum.radzen.com/t/general-question-about-multi-tenancy-in-radzen/20374/11 "2025-05-21T14:50:00Z")

</div>

Yes I understand. But try logging in with tenantUser2 when on localhost:5001. will not be possible because GetTenant() will always return tenant1.

Or in your case [radzen-rocks.com](http://radzen-rocks.com).

Your tenants have hosts like this:

tenant1: localhost:5001, [tenant1.radzen-rocks.com](http://tenant1.radzen-rocks.com)  
tenant2: localhost:5001, [tenant2.radzen-rocks.com](http://tenant2.radzen-rocks.com)

So when user of tenant2 goes to localhost:5001 he cannot login because the code will always return tenant1

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [May 21, 2025, 3:05pm UTC](https://forum.radzen.com/t/general-question-about-multi-tenancy-in-radzen/20374/12 "2025-05-21T15:05:22Z")

</div>

You are right, maybe we should update the code to provide better user discovery during development:

```auto
        public override async Task<ApplicationUser> FindByNameAsync(string normalizedName, CancellationToken cancellationToken = default)
        {
#if DEBUG
            return await base.FindByNameAsync(normalizedName, cancellationToken);
#else
            if (normalizedName.ToLower() == "tenantsadmin")
            {
                return await base.FindByNameAsync(normalizedName, cancellationToken);
            }

            var tenant = GetTenant();
            ApplicationUser user = null;

            if (tenant != null)
            {
                user = await Context.Set<ApplicationUser>().SingleOrDefaultAsync(r => r.NormalizedUserName == normalizedName && r.TenantId == tenant.Id, cancellationToken);
            }

            return user;
#endif
        }

```

---

<div class="post-metadata">

**Author:** ![Murmelmann](https://forum.radzen.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@Murmelmann](https://forum.radzen.com/u/Murmelmann)\
**Post date:** [May 21, 2025, 3:07pm UTC](https://forum.radzen.com/t/general-question-about-multi-tenancy-in-radzen/20374/13 "2025-05-21T15:07:09Z")

</div>

So just be sure, you are saying that in production it is a requirement that each tenant has own defined host (e.g. [client1.myapp.com](http://client1.myapp.com)) and hosts cannot be shared accross tenants, correct?

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [May 21, 2025, 3:09pm UTC](https://forum.radzen.com/t/general-question-about-multi-tenancy-in-radzen/20374/14 "2025-05-21T15:09:07Z")

</div>

Yes, that’s the requirement.
