Getting SearchBoxEx to work on a Branded MySite Host

If you’ve seen the out-of-box MySite Host, you’ll notice that it doesn’t have a normal search box included as part of the master page, and instead just has a Find People search box:

The Find People search box on a MySite Host

When you perform a search with this box, you are taken to the people scope results page (PeopleResults.aspx) in the Search Center that is defined in your User Profile Service Application’s My Site Settings > Setup My Sites page.

If you go to your My Site Host’s Site Settings > Site Collection Administration > Search Settings page, you’ll see that by default it’s configured to not use custom scopes, to not show the scopes dropdown, and to use the OSSSearchResults.aspx page for contextual scopes. The settings on this page are completely ignored by the Find People search box on the MySite Host master page (because it looks to the Search Center configuration in the User Profile Service Application).

MySite Host default search settings

If you dig into the mysite.master, you will not find a SearchBox or SearchBoxEx control, and will find that the PlaceholderSearchArea is set to Visible=”false”:

<div class="s4-die">
    <asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server" Visible="false"/>
    <asp:ContentPlaceHolder id="PlaceHolderGlobalNavigation" runat="server" Visible="false" />
    <asp:ContentPlaceHolder id="PlaceHolderTitleBreadcrumb" runat="server" Visible="false" />
    <asp:ContentPlaceHolder id="PlaceHolderGlobalNavigationSiteMap" runat="server" Visible="false" />
    <asp:ContentPlaceHolder id="PlaceHolderTopNavBar" runat="server" Visible="false" />
    <asp:ContentPlaceHolder id="PlaceHolderHorizontalNav" runat="server" Visible="false" />
</div>

Digging in to the mysite.master, there is a DelegateControl called GlobalNavigation, and if you look at a Feature called MySiteNavigation, you’ll find that it references an ASCX control for this delegate control:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Control Id="GlobalNavigation" Sequence="100" ControlSrc="~/_controltemplates/mysitetopnavigation.ascx" />
</Elements>

Inside mysitetopnavigation.ascx, you’ll find the reference to the Find People search control, which is a PeopleSearchBoxEx control:

  <SPSWC:PeopleSearchBoxEx 
         ID="MySiteGlobalSearchBox"
         FrameType="none" 
         HonorUseSiteDefaults="true"
         IsMysiteSearchBox = "true"
         DropDownMode="HideScopeDD" 
         ShowSearchOptions="false" 
         GoImageUrl="/_layouts/images/ppl_search_normal.png"
         GoImageUrlRTL="/_layouts/images/ppl_search_normal_rtl.png"
         GoImageActiveUrl="/_layouts/images/ppl_search_active.png"
         GoImageActiveUrlRTL="/_layouts/images/ppl_search_active_rtl.png"
         QueryPromptString="<%$Resources:sps,MySiteTopNav_PeopleSearch_Text%>"
         runat="server"/>

If you want to customize the MySite Host branding and include a normal search box with scope dropdown, you’ll want to use your own master page and include the SearchBoxEx directly. Normally this control is included in the PlaceholderSearchArea, but you can include it manually in your masterpage.

Your first inclination might be to include this control, set UseSiteDropDownMode=”true”, UseSiteDefaults=”true” and then enter your search center url and dropdown settings in the Site Collection Administration > Search Settings page, like so:

	<SPSWC:SearchBoxEx id="SearchBox" runat="server" 
	                    GoImageUrl="/_layouts/images/gosearch.gif" 
	                    GoImageUrlRTL="/_layouts/images/gosearch.gif" 
	                    UseSiteDropDownMode="true" 
	                    DropdownWidth="280"
	                    UseSiteDefaults="true"
	                    QueryPromptString="<%$ Resources: SearchStrings, SearchFieldText %>"
	                    FrameType="None" WebPart="true" __WebPartId="{551E15C2-FF48-4670-BC26-FA1BDD992F74}"/>

This is what you would typically use on any other site, like a Publishing portal, so that an admin of the site could have some level of control over the search box and scopes. However if you try this, you will notice that the dropdown for scopes will never appear.

The MySite Host is a special beast and is configured to know about the User Profile Service Application settings, so the right way to go about this is to 1) use the default MySite Host Search settings (no scopes, no dropdown, see screenshot above). Then configure your SearchBoxEx like this:

	<SPSWC:SearchBoxEx id="SearchBox" runat="server" 
	                    GoImageUrl="/_layouts/images/gosearch.gif" 
	                    GoImageUrlRTL="/_layouts/images/gosearch.gif" 
	                    UseSiteDropDownMode="false" 
	                    DropdownWidth="280"
	                    UseSiteDefaults="false"
	                    DropDownMode="ShowDD_NoContextual" 
	                    QueryPromptString="<%$ Resources: SearchStrings, SearchFieldText %>"
	                    FrameType="None" WebPart="true" __WebPartId="{551E15C2-FF48-4670-BC26-FA1BDD992F74}"/>

You can play with the DropDownMode, but personally I like to use ShowDD_NoContextual because the MySite host is not configured to be indexed by the search server, so a contextual scope doesn’t make much sense to offer anyway.