FederatedResultsWebPart Class

Specifies the user interface (UI) control that displays the results for a search query to a federated location.

Inheritance Hierarchy

System.Object
  System.Web.UI.Control
    System.Web.UI.WebControls.WebControl
      System.Web.UI.WebControls.Panel
        System.Web.UI.WebControls.WebParts.Part
          System.Web.UI.WebControls.WebParts.WebPart
            Microsoft.SharePoint.WebPartPages.WebPart
              Microsoft.SharePoint.WebPartPages.BaseXsltDataWebPart
                Microsoft.SharePoint.WebPartPages.DataFormWebPart
                  Microsoft.Office.Server.Search.WebControls.SearchResultsBaseWebPart
                    Microsoft.Office.Server.Search.WebControls.FederatedResultsWebPart

Namespace:  Microsoft.Office.Server.Search.WebControls
Assembly:  Microsoft.Office.Server.Search (in Microsoft.Office.Server.Search.dll)

Syntax

'Declaration
<ComVisibleAttribute(False)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
Public Class FederatedResultsWebPart _
    Inherits SearchResultsBaseWebPart _
    Implements IDesignerEventAccessor
'Usage
Dim instance As FederatedResultsWebPart
[ComVisibleAttribute(false)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public class FederatedResultsWebPart : SearchResultsBaseWebPart, 
    IDesignerEventAccessor

Remarks

Enterprise Search in Microsoft Office SharePoint Server 2007 includes the following new Web Parts for displaying search results from federated locations:

  • Federated Results Web Part
    Displays the results from a specified federated location. You can specify only one location in a Federated Results Web Part. Use the FederatedResultsWebPart class to create a custom version of this Web Part.

  • Top Federated Results Web Part
    Displays the results from the first federated location to return search results. You can configure multiple locations for the Web Part, in priority order. Use the TopFederatedResultsWebPart class to create a custom version of this Web Part.

Examples

The following code example demonstrates how to set the user credentials on the Federated Results Web Part data source for a custom Federated Results Web Part. You must set user credentials in this way for federated locations that are configured to use any of the per-user authentication types, with the exception of Kerberos. For more information, see Creating a Custom Federated Search Web Part with a Credentials UI.

Note

This code example is a simplified version of a custom Federated Results Web Part that does not include the full code needed to prompt the user for their credentials. For an example that demonstrates how to prompt for user credentials, see Custom Federated Search Web Part Sample.

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using Microsoft.Office.Server.Search.WebControls;
using Microsoft.Office.Server.Search.Administration;
using Microsoft.Office.Server.Search.Federation;
using System.Security;
using System.Web.UI.HtmlControls;
using Microsoft.SharePoint;
using System.Xml.Serialization;
using System.Xml.XPath;

namespace CustomFedSearchSample
{
    [XmlRoot(Namespace = "CustomFederatedResultsWebPart")]
    public class SampleFederatedResultsWebPart : FederatedResultsWebPart, IPostBackEventHandler
    {
        protected override void OnLoad(EventArgs e)
        {
            try
            {
                this.ShowMessages = false;
                base.OnLoad(e);
            }
            catch (Exception ex)
            {
                string x = ex.Message.ToString();
            }
        }

        protected override void ConfigureDataSourceProperties()
        {
            ICredentials userCredentials = null;
            base.ConfigureDataSourceProperties();
            FederatedResultsDatasource fedResultsDS = this.DataSource as FederatedResultsDatasource;
            LocationConfiguration locationConfig = null;

            if (fedResultsDS.Location != null)
            {
                string locationName = fedResultsDS.Location;
                LocationConfigurationCollection locations = SearchContext.Current.LocationConfigurations;
                locations.TryGetLocationConfigurationByInternalName(locationName, out locationConfig);

                switch (locationConfig.AuthInfo.AuthenticationType)
                {
                    case FederationAuthType.PerUserFormsAuthentication:
                        //Replace FormsLogonURL with the URL to the Forms logon page.
                        string logonURL = "http://FormsLogonURL";
                        //Replace FormMethod with post or get.
                        string logonMethod = FormMethod";
                        Dictionary<string, string> logonInput = new Dictionary<string, string>();
                        /*
                         *Code to compute logon input names and values for forms
                         *logon page, and add them to the Dictionary object goes here.
                         */ 
                        Dictionary<string, SecureString> logonSecureInput = new Dictionary<string, SecureString>();
                        /*
                         *Code to compute logon input names and System.Security.SecureString values
                         *for forms logon page and add them to the Dictionary object goes here.
                         */ 
                        CookieCollection formsLogonCookies = new CookieCollection();
                        userCredentials = new FormsCredentials(logonURL, logonURL, logonInput, logonSecureInput, logonMethod, formsLogonCookies);
                        break;

                    case FederationAuthType.PerUserCookie:
                        CookieCollection logonCookies = new CookieCollection();
                        /*
                         *Code to compute logon cookies and add them
                         *to the cookie collection goes here.
                         */
                        userCredentials = new CookieCredentials(logonCookies);
                        break;

                    case FederationAuthType.PerUserNTLM:
                    case FederationAuthType.PerUserBasicAuth:
                    case FederationAuthType.PerUserDigest:
                        /*
                         *Replace username< > with the Windows account.
                         *Replace domain with the Windows domain name.
                         *Replace password with the password for the Windows account.
                         */
                        string user = username";
                        string domain = "domain";
                        string password = "password";
                        userCredentials = new NetworkCredential(user, password, domain);
                        break;

                    default:
                        break;
                }
                if (fedResultsDS.UserCredentials.ContainsKey(locationName))
                {
                    fedResultsDS.UserCredentials.Remove(locationName);
                }

                if (userCredentials != null)
                {
                    fedResultsDS.UserCredentials.Add(locationName, userCredentials);
                }
            }
        }

        protected override XPathNavigator GetXPathNavigator(string viewPath)
        {
            XPathNavigator federatedResults;
            federatedResults = base.GetXPathNavigator(viewPath);

            if (federatedResults == null)
            {
                ShowLogonControls();
            }
            else
            {
                ShowLogoutControls();
            }

            return federatedResults;
        }

        private void ShowLogonControls()
        {
            //Code to display logon controls goes here.
        }

        private void ShowLogoutControls()
        {
        //Code to display logout controls
        }
    }
}

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

FederatedResultsWebPart Members

Microsoft.Office.Server.Search.WebControls Namespace

FederatedResultsDataSource

FederatedResultsDatasourceView

TopFederatedResultsWebPart

SearchResultsBaseWebPart

Other Resources

Custom Federated Search Web Part Sample

Federated Search Overview