Invalid Tenancy Name

穿精又带淫゛_ 提交于 2019-12-03 09:15:27

From the documentation on Tenant Management:

AbpTenant class defines some base properties, most important ones are:

  • TenancyName: This is unique name of a tenant in the application. It should not be changed normally. It can be used to allocate subdomains to tenants like 'mytenant.mydomain.com'. Tenant.TenancyNameRegex constant defines the naming rule.
  • Name: An arbitrary, human-readable, long name of the tenant.

TenancyNameRegex is "^[a-zA-Z][a-zA-Z0-9_-]{1,}$" as spaces are not allowed in subdomains.

As quoted above, use Name for the human-readable name (with spaces) of the tenant.

Before saving a tenant, it's being validated against TenancyNameRegex regular expression. Thus a tenant name cannot contain space (by design). Do not remove the regex check, but add a client-side validation to check the tenant name.

protected virtual Task ValidateTenancyNameAsync(string tenancyName)
{
    if (!Regex.IsMatch(tenancyName, AbpTenant<TUser>.TenancyNameRegex))
    {
         throw new UserFriendlyException(L("InvalidTenancyName"));
    }

    return Task.FromResult(0);
}

See the code => https://github.com/aspnetboilerplate/aspnetboilerplate/blob/45fe6d9f38b79ab111eaf2a54b507b87c92e544e/src/Abp.Zero.Common/MultiTenancy/AbpTenantManager.cs#L222

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!