如何:将范围通知控件添加到自定义结果页

上次修改时间: 2010年4月20日

适用范围: SharePoint Server 2010

网站搜索结果页 osssearchresults.aspx 包含范围通知控件。此控件通知用户可用的自定义范围,这使用户能够搜索更广泛的网站范围。Web 部件库中没有提供此控件,因此当您希望在搜索结果页上显示范围通知控件时,必须将此控件的代码添加到该页上。

本主题介绍如何将代码添加到搜索结果页上以显示范围通知控件。

添加范围通知控件

  1. 在 HTML 编辑器(例如 Microsoft SharePoint Designer 2010)或文本编辑器(例如记事本)中打开搜索结果文件。

  2. 通过使用以下代码来添加范围通知控件的标记前缀注册。

    <%@ Register Tagprefix="MSWSC" Namespace="Microsoft.SharePoint.Portal.WebControls" 
    Assembly="Microsoft.Office.Server.Search, Version=14.0.0.0, Culture=neutral, 
    PublicKeyToken=71e9bce111e9429c" %>
    
  3. 使用以下代码将控件添加到页面上

    <MSWSC:searchnotification  runat="server"/>
    
  4. 为网站集启用自定义范围。

    为网站集启用自定义范围

    1. 通过将 /_layouts/settings.aspx 附加到网站集的 URL 来打开网站集的"网站设置"页,如下所示:

      http://SiteCollectionURL/_layouts/settings.aspx

    2. 在"网站设置"页的"网站集管理"部分,单击"搜索设置"。

    3. 在"网站集搜索中心"部分,选择"启用自定义范围",指定要将网站集连接到的搜索中心,然后单击"确定"。

  5. 若要测试范围通知控件代码,请使用本主题的示例一节中的代码来创建空白测试页。然后,在浏览器中导航到测试页,并使用查询字符串中的 k 参数来将搜索查询附加到 URL,如下所示:

    http://SiteURL/pages/ScopesNotificationTest.aspx?k=queryTerm

示例

您可以使用以下代码创建空白页来测试范围通知控件。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ Page Language="C#" %>
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta name="WebPartPageExpansion" content="full" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
</head>
<body>
The scopes notification control should appear below this text:
<%@ Register Tagprefix="MSWSC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.Office.Server.Search, 
Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><MSWSC:searchnotification  runat="server"/>
<form id="form1" runat="server">
</form>
</body>
</html>