SharePoint 中的主机 Web、加载项 Web 和 SharePoint 组件Host webs, add-in webs, and SharePoint components in SharePoint

如果包含 SharePoint 组件的加载项已安装到网站上,则会列于“网站内容”**** 页上,并可从中启动。When an add-in that includes SharePoint components is installed on a website, it is listed on the Site Contents page from which it can be launched. 此列表是加载项的启动点,也是唯一必须添加到网站的内容,尽管可以根据需要添加其他特定内容(如自定义操作或加载项部件)。That listing, which is the launch point of the add-in, is the only required addition to the website, although certain other things can optionally be added, such as a custom action or an add-in part. 若要了解这些启动方法,请参阅通过 UI 访问加载项For information about these options, see Accessing the add-in from the UI.

主机 Web、加载项 Web 和独立域Host webs, add-in webs, and the isolated domain

不同于上述 UI 元素,SharePoint 加载项组件和内容(如列表、内容类型、工作流和页面)部署到位于特殊独立域中的另一个网站。Other than these UI elements, the SharePoint Add-in components and content, such as lists, content types, workflows, and pages, are deployed to a different website in a special isolated domain. 此过程基本上对用户隐藏。This fact is largely hidden from the user. 加载项部署到的特殊网站称为“加载项 Web”。The special website to which the add-in is deployed is called an add-in web. 加载项安装到的网站称为“主机 Web”。The website to which the add-in is installed is called the host web. 虽然加载项 Web 有自己的独立域,但它与主机 Web 位于同一网站集中。Although the add-in web has its own isolated domain, it is in the same site collection as the host web. (不适用此规则的一个例外情况是,加载项通过租户范围进行安装。(One exception to this rule is when the add-in is installed with tenant scope. 在这种情况下,加载项 Web 位于公司加载项目录的网站集中。)In that scenario, the add-in web is in the site collection of the corporate add-in catalog.)

图 1 展示了安装有两个 SharePoint 加载项的主机 Web。Figure 1 shows a host web with two SharePoint Add-ins installed. 加载项 1 有远程组件,但没有 SharePoint 组件,因此也就没有加载项 Web。Add-in 1 has remote components, but no SharePoint components, so it has no add-in web. 加载项 2 没有远程组件,但有两个 SharePoint 列表和一个工作流。Add-in 2 has no remote components, but it has two SharePoint lists and a workflow. 这些内容都已部署到独立子网站(SharePoint 加载项可以同时包含远程组件和 SharePoint 托管组件,尽管此关系图中的两个加载项都不是这样)。These have been deployed to an isolated subsite (a SharePoint Add-in can have both remote and SharePoint-hosted components, although neither add-in in this diagram has both).

图 1:安装了提供程序托管加载项和 SharePoint 托管加载项的主机 WebFigure 1: Host web with a provider-hosted add-in and a SharePoint-hosted add-in

主机 Web、应用程序 Web 及其组件。

例如,假设在具有以下 URL 的主机网站上安装了一个外接程序,此外接程序不仅仅具有 UI 元素,还具有可以部署到主机 Web 的 SharePoint 组件:For example, suppose that an add-in, with SharePoint components beyond just the UI elements that can be deployed to a host web, is installed on a host website at the following URL:

`https://www.fabrikam.com/sites/Marketing`

SharePoint 外接程序将部署到新创建的网站,此网站具有如下所示的 URL:The SharePoint Add-in will be deployed to a newly created website with a URL like the following:

`http://add-in-bdf2016ea7dacb.fabrikamadd-ins.com/sites/Marketing/Scheduler`

请注意,此 URL 的结构如下:Note that this URL has the following structure:

`https://` _Add-in_Prefix_ `-` _Add-in_ID_ `.` _Add-in_Base_Domain_ `/` _Domain_Relative_URL_of_Host_Web_ `/` _Add-in_Name_

这些占位符的定义如下:The placeholders are defined as follows:

  • Add-in_Prefix 是管理中心场管理员设置的任何字符串。默认值为"default"。在此示例中,管理员已经将此值更改为"add-in"。Add-in_Prefix is any string set by the farm administrator in Central Administration. The default is "default." In this example the administrator has changed this to "add-in."

  • Add-in_ID 是安装加载项时内部生成的十六进制数。Add-in_ID is a hexadecimal number generated internally when the add-in is installed.

  • Add-in_Base_Domain 是场管理员在管理中心内或使用 SharePoint 命令行管理程序设置的任意字符串。Add-in_Base_Domain is any string set by the farm administrator in Central Administration or with SharePoint Management Shell. 得将此设置为 SharePoint Web 应用的子域,否则加载项隔离目的基本上就会落空。This should not be set to a subdomain of the SharePoint web application or the purpose of add-in isolation is largely defeated. 在此示例中,管理员已删除“www.”,In this example, the administrator has removed the "www." 并向公司名称添加了“add-ins”。and added "add-ins" to the company name. 因此,加载项基域是 fabrikamadd-ins.comSo fabrikamadd-ins.com is the add-in base domain.

  • Domain_Relative_URL_of_Host_Web 是父主机 Web 的相对 URL,在此示例中是 sites/MarketingDomain_Relative_URL_of_Host_Web is the relative URL of the parent host web, in this case sites/Marketing.

  • Add-in_Name 是 appmanifest.xml 文件中的 App 元素的 Name 属性的值。Add-in_Name is the value of the Name attribute of the App element in the appmanifest.xml file.

将 SharePoint 组件部署到外接程序 Web 而非主机 Web 的主要原因有两个。这两个原因均与安全有关。There are two primary reasons why SharePoint components are deployed to add-in webs, rather than the host web. Both are related to security.

  • 外接程序权限强制: 在 SharePoint 外接程序的模型 中,外接程序具有其自己的标识,并且具有权限,这些权限未必与执行该外接程序的用户的权限相同。安装外接程序时会请求这些外接程序权限,并且这些权限由安装外接程序的人员授予,前提是人员具有外接程序请求的所有权限。(如果正在安装外接程序的用户没有外接程序请求的所有权限,则用户无法安装外接程序。)通过为每个外接程序提供其自己的域,SharePoint 可以可靠地标识外接程序提出的请求,并验证外接程序的权限。有关外接程序权限的详细信息,请参阅 加载项权限Enforcement of add-in permissions: In the model for SharePoint Add-ins, an add-in has its own identity and it has permissions that are not necessarily the same as the permissions of the user who is executing the add-in. These add-in permissions are requested when the add-in is installed and granted by the person who installs the add-in, as long as person has all the permissions that the add-in requests. (If the user who is installing the add-in does not have all the permissions that are requested by the add-in, the user cannot install the add-in.) By giving each add-in its own domain, SharePoint can reliably identify requests made by the add-in and verify the permissions of the add-in. For more information about add-in permissions, see Add-in permissions.

  • 跨域脚本安全性: 对于 JavaScript 方法调用,现代浏览器支持"相同的源策略"。通过将每个 SharePoint 外接程序部署到其自己的域,SharePoint 可以利用浏览器的相同源策略,以确保 SharePoint 外接程序中的 JavaScript 不会执行任何其他域(从最终用户的角度来看,包括在其中安装了该外接程序的域)中的任何 JavaScript。Cross-domain scripting security: Modern browsers support a "same origin policy" with regard to JavaScript method calls. By deploying each SharePoint Add-in to its own domain, SharePoint takes advantage of the browser's same origin policy to ensure that JavaScript in the SharePoint Add-in cannot execute any JavaScript from any other domain, including the domain in which, from the end-user's perspective, the add-in is installed.

    SharePoint 还支持安全克服策略限制。SharePoint also provides a means of safely overcoming the limits of the policy. 这样一来,SharePoint 加载项的远程组件可以从主机 Web 和加载项 Web 的公共父租赁中的任何网站查询数据等。Among other things, this enables the remote components of a SharePoint Add-in to query data from any website in the common parent tenancy of the host and add-in webs. 有关详细信息,请参阅使用跨域库从加载项访问 SharePoint 数据For more information, see Access SharePoint data from add-ins using the cross-domain library.

SharePoint 加载项中可以包含的 SharePoint 组件类型Types of SharePoint components that can be in a SharePoint Add-in

一般情况下,SharePoint 加载项可以包含下面列出的一个或多个组件。In general, a SharePoint Add-in can contain one or more of the components in the following list. 除有一些例外情况外,这些组件必须部署到 SharePoint 解决方案包 (.wsp) 文件内的 Web 范围功能中。With certain exceptions, these components must be deployed in Web-scoped Features that are inside a SharePoint solution package (.wsp) file.

备注

在本文稍后将介绍的部署 SharePoint 组件的注意事项部分中,将会更详细地介绍标有星号 (*) 的组件。The components that are marked with an asterisk (*) are discussed in more detail in the section Caveats for deploying SharePoint components later in this article.

  • 功能(仅限 Web 范围)Features (Web-scoped only)
  • 自定义操作(包括快捷菜单项和功能区自定义)*Custom actions (including shortcut menu items and ribbon customizations)*
  • 远程事件接收器*Remote event receivers*
  • 引用 SharePoint 中所包含的 Web 部件(包括加载项部件,但不是自定义 Web 部件)的标记*Markup that references web parts, including add-in parts, that are included in SharePoint (but not custom web parts)*
  • 供 SharePoint 页面使用的自定义级联样式表 (CSS) 文件Custom cascading style sheets (CSS) files for use by SharePoint pages
  • 要供 SharePoint 页面使用的自定义 JavaScript 文件Custom JavaScript files for use by SharePoint pages
  • 模块(文件集)Modules (sets of files)
  • 页面Pages
  • 列表模板List templates
  • 列表和库实例List and library instances
  • 自定义列表表单Custom list forms
  • 自定义列表视图Custom list views
  • 自定义内容类型Custom content types
  • 字段(属于 SharePoint 中内置的字段类型)Fields (of field types that are built into SharePoint)
  • Microsoft Business Connectivity Services (BCS) 模型(仅限 Web 范围)、基于此模型的外部内容类型和使用这些内容类型的外部列表*Microsoft Business Connectivity Services (BCS) models (Web-scoped only), external content types based on the model, and external lists that use the content types*
  • 工作流*Workflows*
  • 属性包Property bags
  • Web 模板(但不是网站定义)*Web templates (but not site definitions)*

不得在 SharePoint 加载项中部署其他任何类型的 SharePoint 组件。No other kind of SharePoint component can be deployed in a SharePoint Add-in. 若要详细了解有关 SharePoint 加载项可包含内容的限制,请参阅 SharePoint 加载项与 SharePoint 解决方案对比For more information about restrictions on what can be included in a SharePoint Add-in, see SharePoint Add-ins compared with SharePoint solutions.

部署 SharePoint 组件的注意事项Caveats for deploying SharePoint components

下面是与在外接程序中部署某些 SharePoint 组件类型有关的一些注意事项和详细信息。The following are some caveats and details concerning the deployment of certain kinds of SharePoint components in an add-in:

  • 自定义操作: 除了可以将自定义操作添加到外接程序 Web 中之外,也可以将其添加到主机 Web 中。为了将自定义操作添加到外接程序 Web 中,您可以将其包括在 .wsp 文件内的 Web 范围功能中,就像可包括添加到外接程序 Web 中的任何其他组件一样。为了将自定义操作添加到主机 Web 中,您可以(甚至在外部外接程序中)将 CustomAction 标记包括在位于外接程序包内但在任何 .wsp 文件之外的功能中。此类"散装"功能中的组件适用于主机 Web,不适用于外接程序 Web,因此此类型的功能称为主机 Web 功能。Custom actions: In addition to adding custom actions to the add-in web, you can add them to the host web as well. To add the custom action to the add-in web, you include it in a Web-scoped Feature that is inside a .wsp file, just as you would include any other component you add to the add-in web. To add a custom action to the host web, you can include (even in an externally based add-in) CustomAction markup in a Feature that is in the add-in package but outside any .wsp file. Components in such a "loose" Feature apply to the host web, not the add-in web, so this type of Feature is called ahost web Feature.

  • Web 部件: 可以在加载项中部署一种 Web 部件(加载项部件),加载项部件可以转至加载项 Web 或主机 Web。在加载项中可以引用所有其他类型的 Web 部件,但加载项不会部署这些部件。如果将加载项部件部署到主机 Web,则应该将其包括在主机 Web 功能中。Web Parts: One kind of web part, an add-in part, can be deployed in an add-in, and an add-in part can go to either the add-in web or the host web. All other types of web parts can be referenced in add-ins, but not deployed by them. If an add-in part is deployed to the host web, it should be included in a host web Feature.

  • 远程事件接收器: 这些是 SharePoint 中的新增内容,它们与经典的 SharePoint 事件接收器相似,不同的是代码在云中运行。在 SharePoint 托管的外接程序中无法使用这些接收器。Remote event receivers: These are new in SharePoint. They resemble classic SharePoint event receivers except that the code runs in the cloud. These are not available in a SharePoint-hosted add-in.

  • 工作流: SharePoint 中的工作流使用 Microsoft Azure 托管的工作流运行时,此工作流运行时是 SharePoint 中的新增内容。使用 SharePoint 承载的工作流运行时的编码工作流无法包括在 SharePoint 外接程序中。只允许存在声明性工作流或使用较新运行时的工作流。Workflows: Workflows in SharePoint use the Microsoft Azure-hosted workflow runtime that is new in SharePoint. Coded workflows that use the SharePoint-hosted workflow runtime cannot be included in a SharePoint Add-in. Only declarative workflows or workflows that use the newer runtime are allowed.

  • Microsoft Business Connectivity Services (BCS) 模型、外部内容类型和外部列表: Business Data Connectivity (BDC) Service 模型通常具有比网站集更广的范围。Microsoft Business Connectivity Services (BCS) models, external content types, and external lists: Business Data Connectivity (BDC) service models typically have a scope that is wider than a site collection. 不过,如果 BDC Service 模型部署到加载项中,它的范围只能是加载项 Web。However, when a BDC service model is deployed in an add-in, its scope is limited to the add-in web. 加载项中的 BDC Service 模型不会存储在 BDC Service 共享的服务存储中,When a BDC service model is included in an add-in, it is not stored in the BDC service shared service store. 而是在加载项 Web 中以文件形式存储。Instead, it is stored as a file in the add-in web.

  • Web 模板: 在大多数情况下,都希望加载项 Web 实例化更适合加载项 Web 的新内置网站定义配置 APP#0Web Templates: In most cases, you will want the add-in web to instantiate the new built-in site definition configuration APP#0, which is optimized for add-in webs. (有关详细信息,请参阅通过 UI 访问加载项。)如果加载项包没有 WebTemplate 元素,SharePoint 就会自动使用 APP#0(For more information, see Accessing the add-in from the UI.) SharePoint automatically uses APP#0 when the add-in package does not include a WebTemplate element.

    还可以为加载项 Web 定义自定义网站类型。为此,主要需要执行下面的两个步骤:You can also define a custom site type for the add-in web. There are two major steps to doing this:

    备注

    加载项清单的新 WebTemplate 元素与功能中可包含的 WebTemplate 元素不是同一标记。The new WebTemplate element for add-in manifests is not the same markup as the WebTemplate element that can be included in Features. 功能中可包含的 WebTemplate 元素定义了网站类型,而加载项清单的 WebTemplate 元素则直接确定了要使用的网站类型。The WebTemplate element that can be included in Features defines a type of site, but the WebTemplate element for add-in manifests simply identifies what type of site to use. 若要详细了解 SharePoint 加载项的加载项清单,请参阅加载项包结构For more information about the add-in manifest of a SharePoint Add-in, see Add-in package structure.

    注意

    请不要使用外接程序清单中的 WebTemplate 元素将任何内置 SharePoint 网站定义配置指定为外接程序 Web 的网站类型。我们不支持对外接程序 Web 使用除 APP#0 之外的任何内置网站定义配置。Do not use the WebTemplate element in the add-in manifest to designate any of the built-in SharePoint site definition configurations as the add-in web's site type. We do not support using any of the built-in site definition configurations, other than APP#0, for add-in webs.

    若要详细了解网站定义配置和 Web 模板,请参阅使用网站模板和定义For more information about site definition configurations and web templates, see Working with Site Templates and Definitions.

另请参阅See also