Invalid Tenancy Name

北慕城南 提交于 2019-12-09 07:20:18

问题


I am working on an ASP.NET Boilerplate service project.

When I am saving a client, it returns an error:

Tenancy Name is not valid

The tenancy name contains spaces. TenantDto maps to Tenant object without any error. Database table TenancyName column is nvarchar(64). Error occurs when it is saving.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/47990380/invalid-tenancy-name

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