MultiTenant for ASP.NET Core

Middleware, request-based strategies, and per-tenant authentication for ASP.NET Core apps.

MultiTenant ASP.NET Core resolves the tenant for every request from the host, route, header, claim, or session, and makes it available to the rest of the pipeline.

It includes the core MultiTenant package, so this is the only package a typical web app needs to start.

dotnet add package Finbuckle.MultiTenant.AspNetCore
builder.Services.AddMultiTenant<AppTenantInfo, string>()
    .WithHostStrategy()
    .WithConfigurationStore();

var app = builder.Build();

app.UseMultiTenant<string>();

Releases

Version Targets Released Release notes
v11.0.0New .NET 11 Nov 24, 2026 Release notes
v10.2.0 .NET 10 Nov 12, 2026 Release notes
v9.4.16 .NET 8 and 9 Nov 10, 2026 Release notes
v8.1.21 .NET 6, 7, and 8 Nov 10, 2026 Release notes

All versions on NuGet · All releases on GitHub

Resolve the tenant on every request

Strategies decide which tenant a request belongs to. Configure one or several, and MultiTenant tries them in order until a store recognizes the identifier.

  • Host and subdomain, route parameter, base path, header, claim, and session strategies.
  • Delegate and custom strategies for any other source of tenant identity.
  • A static strategy as a fallback or default tenant.
Explore strategies
builder.Services.AddMultiTenant<AppTenantInfo, string>()
    // https://initech.example.com
    .WithHostStrategy()
    // https://example.com/initech/home
    .WithRouteStrategy()
    // X-Tenant: initech
    .WithHeaderStrategy("X-Tenant")
    .WithConfigurationStore();

Middleware that fits your pipeline

Add one middleware before authentication and everything after it knows the tenant. Decide what happens to requests that don't need one, or don't have one.

  • Exclude endpoints, controllers, or groups from tenant resolution.
  • Bypass resolution with your own condition, such as health checks.
  • Short-circuit or redirect when no tenant is found.
Read about ASP.NET Core integration
builder.Services.AddMultiTenant<AppTenantInfo, string>()
    .WithHostStrategy()
    .WithConfigurationStore()
    .ShortCircuitWhenTenantNotResolved();

var app = builder.Build();

app.UseMultiTenant<string>();
app.UseAuthentication();
app.UseAuthorization();

app.MapHealthChecks("/health")
    .ExcludeFromMultiTenantResolution();

Authentication that respects tenant boundaries

One call sets up per-tenant authentication from properties on your tenant type, so each tenant can sign in its own way.

  • Cookies carry a tenant claim, so a sign-in for one tenant isn't accepted by another.
  • Per-tenant cookie paths and default challenge scheme.
  • Per-tenant OpenID Connect authority, client ID, and client secret.
Read about per-tenant authentication
builder.Services.AddMultiTenant<AppTenantInfo, string>()
    .WithHostStrategy()
    .WithConfigurationStore()
    .WithPerTenantAuthentication();

builder.Services.AddAuthentication()
    .AddCookie()
    .AddOpenIdConnect();

The current tenant, wherever you need it

Read the tenant from HttpContext in endpoints, controllers, Razor Pages, and middleware, or inject it anywhere through dependency injection.

  • HttpContext helpers for the tenant info and tenant context.
  • Works with minimal APIs, MVC controllers, and Razor Pages.
  • Inject ITenantContext into any service resolved during the request.
Read about getting the current tenant
app.MapGet("/", (HttpContext http) =>
{
    var tenant = http.GetTenantInfo<AppTenantInfo, string>();

    return tenant is null
        ? Results.NotFound()
        : Results.Ok($"Welcome to {tenant.Name}");
});

The rest of the MultiTenant family

MultiTenant Abstractions

Finbuckle.MultiTenant.Abstractions

The shared contracts: tenant info, strategy, store, and tenant context interfaces, with no implementation dependencies.

Learn more

MultiTenant

Finbuckle.MultiTenant

The foundation: tenant resolution, tenant stores, per-tenant options, and running work as a tenant in any .NET app.

Learn more

MultiTenant for EF Core

Finbuckle.MultiTenant.EntityFrameworkCore

Per-tenant data isolation for EF Core, in a shared database, a database per tenant, or a mix of both.

Learn more

MultiTenant Identity

Finbuckle.MultiTenant.Identity.EntityFrameworkCore

Multi-tenant ASP.NET Core Identity: each tenant gets its own users, roles, and passkeys.

Learn more