Docs
Tenantry CoreAPI reference

SubdomainTenantResolver class

Namespace: Tenantry.AspNetCore · Package: Tenantry.AspNetCore · API reference

Resolves the tenant from the subdomain of the request host. For example, acme.app.example.com resolves to acme.

Without SubdomainTenantResolverOptions.BaseDomains, the first label of a host with at least three labels is the tenant: acme.example.com resolves to acme, and example.com, localhost and acme.localhost resolve nothing. With them, only a host of exactly one label followed by a base domain resolves: with example.com, acme.example.com resolves to acme, while example.com, other.org and x.acme.example.com resolve nothing.

A subdomain in SubdomainTenantResolverOptions.IgnoredSubdomains (www by default) and a host that is an IP address resolve nothing. The subdomain is returned in lower case, as host names are compared without regard to case, and an international domain name is compared and returned in its ASCII form (xn--…).

public sealed class SubdomainTenantResolver : ITenantResolver

Implements ITenantResolver.

Constructors

SubdomainTenantResolver()

Creates a resolver with the default options.

public SubdomainTenantResolver()

SubdomainTenantResolver(SubdomainTenantResolverOptions)

Creates a resolver with the given options, copied when it is created.

public SubdomainTenantResolver(SubdomainTenantResolverOptions options)

Parameters:

Methods

ResolveAsync(HttpContext, CancellationToken)

Attempts to read a tenant identifier from the current request.

public ValueTask<string?> ResolveAsync(HttpContext context, CancellationToken cancellationToken = default)

Parameters:

  • context HttpContext: The current HTTP context.
  • cancellationToken CancellationToken: Cancellation token.

Returns: ValueTask<string>: The identifier, or null (or an empty string) if this resolver cannot determine the tenant from the current request. Return it as the request carries it: the tenant store finds the tenant it names.

On this page