Create a new Multi-Tenant Application(创建一个新的多租户应用程序)
Use XAF Application Builder to Create a New Application(使用XAF应用程序生成器创建新应用程序)
In XAF Solution Wizard, proceed until the Choose Options page. On this page, select Multi-Tenancy Application and proceed to complete the wizard.
在XAF解决方案向导中,一直进行到“选择选项”页面。在该页面上,选择“多租户应用程序”,然后继续完成向导。
Note that not all application configurations support multi-tenancy. See Limitations for more information.
请注意,并非所有应用程序配置都支持多租户。有关更多信息,请参阅“限制”。
Create and Initialize the Host Database(创建并初始化主机数据库)
Follow the steps below to create and initialize the Host Database.
按照以下步骤创建并初始化主机数据库。
If required, change the ConnectionString setting in the application configuration file (appsettings.json in Blazor and App.config in WinForms).
如果需要,请更改应用程序配置文件中的连接字符串设置(Blazor 中为 appsettings.json,WinForms 中为 App.config)。
Run the application in Debug mode and log in as Admin with a blank password. The framework executes the following tasks:
以调试模式运行应用程序,并使用空白密码以管理员身份登录。该框架执行以下任务:
-
Creates the Host Database.
创建主机数据库。 -
Creates the Super Administrator user with the login “Admin” and a blank password.
创建登录名为“Admin”且密码为空的超级管理员用户。 -
Switches the application to Host UI mode.
将应用程序切换到主机用户界面模式。
XAF Solution Wizard generates Module Updater code that creates an Admin user with a blank password. For security reasons, this user is not available if the application is compiled in Release configuration.
XAF解决方案向导生成的模块更新程序代码会创建一个密码为空的管理员用户。出于安全考虑,如果应用程序是在发布配置中编译的,则此用户不可用。
After you log in to the Host UI for the first time, we recommend that you change the Super Administrator’s password. You can also create additional Super Administrator accounts. These accounts must be assigned the Administrators role.
首次登录主机用户界面后,建议您更改超级管理员密码。您也可以创建其他超级管理员账户。这些账户必须被赋予管理员角色。
Create and Initialize Tenants(创建并初始化租户)
Follow the steps below to create a new tenant (named “company1.com” in this example).
按照以下步骤创建一个新租户(在此示例中名为“company1.com”)。
In the Host UI, switch to the Tenants List View and add a new Tenant record. Specify the tenant name and a connection string for a new Tenant Database.
在主机用户界面中,切换到租户列表视图并添加一条新的租户记录。指定租户名称以及新租户数据库的连接字符串。
Log out from the Host UI and log in as the new tenant’s administrator (“admin@company1.com”) with a blank password. The framework executes the following tasks:
从主机用户界面注销,然后使用空密码以新租户的管理员(“admin@company1.com”)身份登录。该框架将执行以下任务:
-
Creates a database for tenant company1.com.
为租户company1.com创建一个数据库。 -
In this database, creates the following two users: “admin@company1.com” with the Administrators role and “user@company1.com” with the Users role.
在这个数据库中,创建以下两个用户:具有管理员角色的“admin@company1.com”和具有用户角色的“user@company1.com”。
Take the following additional considerations into account:
考虑以下其他注意事项:
-
Ensure that none of the tenants share their databases with other tenants. A Tenant Database must also never be the same as the Host Database.
确保没有租户与其他租户共享其数据库。租户数据库也绝不能与宿主数据库相同。 -
An application does not immediately create a Tenant Database when the tenant is created. Instead, the database is created when a user logs in to this tenant for the first time.
应用程序在租户创建时不会立即创建租户数据库。相反,数据库是在用户首次登录到该租户时创建的。 -
A tenant name must be unique.
租户名称必须是唯一的。 -
XAF Solution Wizard generates Module Updater code that creates the Admin@tenant_name and Usern@tenant_name users with blank passwords. For security reasons, these users are not available if the application is compiled in Release configuration.
XAF解决方案向导生成的模块更新程序代码会创建密码为空的Admin@tenant_name和Usern@tenant_name用户。出于安全考虑,如果应用程序是在发布配置中编译的,则这些用户不可用。 -
After the first login to the Tenant User Interface, it is recommended that you change passwords for all automatically created users.
首次登录租户用户界面后,建议您更改所有自动创建用户的密码。
Create Tenant Users and Manage Access Permissions(创建租户用户并管理访问权限)
Tenant users and their access permissions are managed in the Tennant User Interface independently from other tenants and from the Host User Interface. Each tenant has its own independent list of users, roles, and security permissions.
租户用户及其访问权限在租户用户界面中进行管理,与其他租户以及主机用户界面相互独立。每个租户都有其独立的用户列表、角色和安全权限。
To create a new Tenant User in a company1.com tenant, you need to:
要在company1.com租户中创建新的租户用户,您需要:
1.Log in with a tenant administrator account (admin@company1.com).
使用租户管理员账户(admin@company1.com)登录。
2.Create a user with the standard user editing interface (the same as in a single-tenant XAF application).
使用标准用户编辑界面(与单租户XAF应用程序中的界面相同)创建用户。
When you create tenant users, we recommend that you pay special attention to how you specify user logins. For example, if you use TenantByUserNameResolver or TenantByEmailResolver to determine user tenants, a user’s login must be specified in accordance with the exact name and format of their tenant. Otherwise, the system will not be able to identify the tenant on the user’s login attempt, which will make the user unable to log in.
当你创建租户用户时,建议你特别注意指定用户登录名的方式。例如,如果你使用TenantByUserNameResolver或TenantByEmailResolver来确定用户租户,那么必须按照租户的确切名称和格式指定用户的登录名。否则,系统将无法在用户尝试登录时识别租户,从而导致用户无法登录。