Skip to content

When running Orchard, you most often will run a single site in a single application domain (app domain),

运行Orchard时,您通常会在单个应用程序域(app域)中运行单个站点,

which in ASP.NET terms is an isolation boundary between applications.

在ASP.NET术语中,它是应用程序之间的隔离边界。

However, Orchard provides an additional isolation boundary between sites,

但是,Orchard在站点之间提供了额外的隔离边界,

referred to as multi-tenancy, that allows you to run multiple Orchard sites within a single ASP.NET app domain.

称为_multi-tenancy_,它允许您在单个ASP.NET应用程序域中运行多个Orchard站点。

This is useful because app domains are generally expensive to initialize, tear down,

这很有用,因为app域通常很难初始化,拆除,

and recycle from memory usage standpoint.

并从内存使用的角度回收。

Running multiple isolated Orchard sites in a single app domain can allow more sites to fit on a single server,

在单个应用程序域中运行多个隔离的Orchard站点可以允许更多站点适合单个服务器,

which is favored by hosting providers to keep costs down.

主机提供商倾向于降低成本。

The assumption is that cost savings for hosting providers result in lower cost for hosting customers.

假设托管服务提供商的成本节约导致托管客户的成本降低。

Multi-tenancy is particularly nice in a Windows Azure environment,

多租户在[Windows Azure环境](Deploying-Orchard-to-Windows-Azure)中特别好用,

because one deployment to Azure can easily support multiple websites.

因为Azure的一个部署可以轻松支持多个网站。

Note: If you want to set up a multi-tenant test site on your local machine, first read

注意:如果要在本地计算机上设置多租户测试站点,请先阅读

Testing Multi-Tenancy on a Local Machine later in this article.

[在本地计算机上测试多租户](/ Documentation /设置多租户 - Orchard-site #test-ten-tenancy-on-a-local-machine)本文后面的内容。

Enabling Multi-Tenancy

启用多租户

By default, the multi-tenancy feature is not enabled when you install Orchard.

默认情况下,安装Orchard时不启用多租户功能。

To enable multi-tenancy, open the Orchard dashboard, click Modules,

要启用多租户,请打开Orchard仪表板,单击 Modules

find the Multi Tenancy feature under Hosting, and then click Enable.

Hosting 下找到 Multi Tenancy 功能,然后单击 Enable

Once multi-tenancy is enabled, you see a Tenants dashboard menu section.

启用多租户后,您会看到租户仪表板菜单部分。

A tenant refers to a separate site configuration inside of the default tenant,

_tenant_指的是默认租户内部的单独站点配置,

which is initial site created after you install Orchard.

这是安装Orchard后创建的初始站点。

You can think of the default tenant as the landlord of an apartment building

您可以将默认租户视为公寓楼的房东

who can provision new apartments and decide the terms for each tenant,

谁可以提供新公寓并决定每个租户的条款,

and the individual tenants as inhabitants of each apartment.

每个公寓的居民和个人租户。

Adding Tenants

添加租户

Initially, you will only have a single tenant, which is the Default tenant.

最初,您将只有一个租户,即默认租户。

To provision another tenant site, click Add a Tenant.

要配置其他租户站点,请单击添加租户

The Add New Tenant screen asks for the name of the tenant (the name may not contain spaces),

添加新租户屏幕要求提供租户名称(名称可能不包含空格),

and the host domain that will map to the tenant. As the landlord for your tenants,

以及将映射到租户的主机域。作为租户的房东,

you decide whether the tenant should be allowed to configure the database (on the Orchard setup screen),

您决定是否允许租户配置数据库(在Orchard设置屏幕上),

or whether you want to configure the database on behalf of the tenant.

或者您是否要代表租户配置数据库。

After you've decided how to provision your new tenant site, click Save.

在确定如何配置新租户网站后,请单击保存

Under List of Site's Tenants you see the new tenant.

网站租户名单下,您会看到新租户。

To provision the new tenant site, click Set Up.

要配置新租户站点,请单击设置

The Orchard setup screen is displayed, as if you were setting up a brand new Orchard installation.

显示Orchard设置屏幕,就像您正在设置全新的Orchard安装一样。

However, the database options are not displayed, because they were decided when the tenant was added.

但是,不显示数据库选项,因为它们是在添加租户时决定的。

Note: If you decide to use an existing database for your tenant, you will be asked for the connection

注意:如果您决定为租户使用现有数据库,则会要求您提供连接

string and for a table prefix. The table prefix will be added to each of the tenant's tables within the database:

字符串和表前缀。表前缀将添加到数据库中的每个租户表中:

Working with Tenant Sites

与租户网站合作

Isolated tenants can each have a unique configuration of content items, enabled features, and applied themes.

隔离的租户可以各自具有内容项,启用的功能和应用主题的唯一配置。

Tenants all share the same file system view of the application, however, so the list of available modules

但是,租户都共享应用程序的相同文件系统视图,因此可用模块列表

and themes will be the same for each tenant.

每个租户的主题和主题都是相同的。

In the following screenshots, the Alpha tenant and the Beta tenant have different themes applied.

在以下屏幕截图中, Alpha 租户和 Beta 租户应用了不同的主题。

You can take a tenant site offline at any time.

您可以随时使租户网站脱机。

Under List of Site's Tenants for your default site, click Suspend for the site you want to take offline.

默认站点的站点租户列表下,单击要暂停的站点的暂停**。

To bring the tenant site back online, click Resume.

要使租户站点重新联机,请单击 Resume

Removing Tenants

删除租户

Currently, there is no UI to remove a tenant, but it can be done by going to the App_Data/Sites

目前,没有用于删除租户的UI,但可以通过转到“App_Data / Sites”来完成

directory of the site, locating the subdirectory for the tenant to remove, and then deleting it.

站点的目录,找到要删除的租户的子目录,然后将其删除。

You might want to move the folder to a backup location in case you need to restore it later.

您可能希望将文件夹移动到备份位置,以备日后需要还原时使用。

Note: On Azure, there is currently no way to remove a tenant except by removing the actual

注意:在Azure上,除了删除实际内容之外,目前无法删除租户

database and the configuration from BLOB storage.

数据库和BLOB存储的配置。

Testing Multi-Tenancy on a Local Machine

在本地计算机上测试多租户

If you are running locally and do not have a domain to map, you can edit your

如果您在本地运行并且没有要映射的域,则可以编辑您的

\Windows\System32\drivers\etc\hosts file to create a sample host.

The following advice is for Windows 10, 7 or Windows Vista and was taken from

以下建议适用于Windows 10,7或Windows Vista,并取自

Orchard Issue Tracker on GitHub.

[GitHub上的Orchard问题跟踪器](https://github.com/OrchardCMS/Orchard/issues/1053)。

These instructions assume that you're using WebMatrix and IIS Express to work with Orchard.

这些说明假定您使用WebMatrix和IIS Express与Orchard一起使用。

  1. Open the \Windows\System32\drivers\etc\ folder.

1.打开\\ Windows \\ System32 \\ drivers \\ etc \\文件夹。

  1. Right-click the hosts file and give yourself modify permissions to that file.

2.右键单击_hosts_文件,并为自己修改该文件的权限。

  1. Open the hosts file in a text editor.

3.在文本编辑器中打开_hosts_文件。

  1. Add the following line, replacing mydemo with the domain name you want to use:

4.添加以下行,将mydemo替换为您要使用的域名:

127.0.0.1 mydemo

  1. Open the \Users\\[YourUserName\]\Documents\IISExpress\config\ folder.

5.打开\\ Users \\\\ [YourUserName \\] \\ Documents \\ IISExpress \\ config \\文件夹。

  1. Open the Applicationhost.config file in a text editor.

6.在文本编辑器中打开Applicationhost.config文件。

  1. Locate the section for your existing Orchard site, such as the following:

7.找到现有Orchard站点的部分,如下所示:

`<site name="mydemo" id="nnnnnnnnn"/>`

  1. Under the <bindings> section, leave the default localhost binding,

8.在<bindings>部分下,保留默认的localhost绑定,

but copy it onto the next line and edit it to read:

但将其复制到下一行并编辑为:

`<binding protocol="http" bindingInformation="*:28923:mydemo" />`

  1. Substitute the port number above for the one you copied from the default localhost binding.

9.将上面的端口号替换为从默认localhost绑定复制的端​​口号。

If you do not want to run WebMatrix with admin privileges (which is not a good practice for security reasons),

如果您不想使用管理员权限运行WebMatrix(出于安全原因这不是一个好习惯),

you need to follow the steps outlined in the article

您需要按照文章中列出的步骤操作

Handling URL Binding Failures in IIS Express as follows:

[处理IIS Express中的URL绑定失败](http://learn.iis.net/page.aspx/1005/handling-url-binding-failures-in-iis-express/)如下:

  1. Open a command window that has administrative privileges.

1.打开具有管理权限的命令窗口。

In Windows 10: Start Menu > All Apps > Windows System > Command Prompt > Right-click the program shortcut and then click Run as administrator.

<font color=#0099ff size=4 face="黑体">在Windows 10中:**开始菜单**&gt; **所有应用**&gt; ** Windows系统**&gt; **命令提示符**&gt;右键单击程序快捷方式,然后单击**以管理员身份运行**。</font>




<font color=#0099ff size=4 face="黑体"></font>

In Windows 7 and Vista: Start Menu > All Programs > Accessories > Command Prompt > Right-click the program shortcut and then click Run as administrator.

<font color=#0099ff size=4 face="黑体">在Windows 7和Vista中:**开始菜单**&gt; **所有程序**&gt; **配件**&gt; **命令提示符**&gt;右键单击程序快捷方式,然后单击**以管理员身份运行**。</font>

  1. Run the following command:

2.运行以下命令:

`> netsh http add urlacl url=http://mydemo:28923/ user=everyone`

This can later be removed with the following command:

稍后可以使用以下命令删除它:

`> netsh http delete urlacl url=http://mydemo:28923/`

Alternatively, you could run WebMatrix using admin privileges as follows:

或者,您可以使用管理员权限运行WebMatrix,如下所示:

  • Open WebMatrix with admin privileges. (Right-click the shortcut in Windows, then click Run as administrator.)

  • 使用管理员权限打开WebMatrix。 (右键单击Windows中的快捷方式,然后单击以管理员身份运行。)

Finally:

最后:

  1. Open your site and attempt to start it.

1.打开您的站点并尝试启动它。

  1. Locate the IIS Express icon in the taskbar and right-click it. You see your site name,

2.在任务栏中找到IIS Express图标,然后右键单击它。你看到你的网站名称,

where you can select to open it via its additional URL.

您可以选择通过其附加URL打开它。

Remember to remove the item from the hosts file or comment out the line using

请记住从_hosts_文件中删除该项目或使用注释掉该行

the # character if you want to view the live site from the same domain name after you've deployed it to an ISP.

如果要在将部署到ISP后从同一域名查看实际站点,请使用#字符。

You need to be very careful that you are looking at the remote site rather than the local one.

您需要非常小心,您正在查看远程站点而不是本地站点。

Consider adding something to one or other of the themes to make the difference immediately apparent.

考虑在一个或另一个主题中添加一些东西,以使差异立即显现出来。

Note: Alternatively, instead of editing the hosts file, you can use the URL *.127-0-0-1.org.uk,

注意:或者,您可以使用URL _ * .127-0-0-1.org.uk_,而不是编辑_hosts_文件,

where * is the name of your tenant or another name of your choosing.

其中*是您的租户的名称或您选择的其他名称。

This will loop back to localhost and is sufficient for testing multi-tenancy locally.

这将循环回localhost,足以在本地测试多租户。