Nick Hadlee's Blog on SharePoint and Other Occasional Rants…

An Alternative Method for Using Custom Master Pages with Search in SharePoint 2010
November 6, 2010, 3:41 pm
Filed under: 2010, Cutomisation, Development, Search

Search is a fundamental component of any SharePoint solution and 2010 has some subtle differences and great improvements over its 2007 predecessor:

  1. One improvement are refiners, a new part of the search user interface (formerly known as facets), which allow you refine the search results based on metadata and even better they are extensible
  2. One important difference between 2007 and 2010 is the use of a specific master page in the Search Centres – the minimal.master master page

I’m not a big fan of minimal.master used within the Enterprise Search Centre so that’s the focus of the rest of this post. I’ll propose a way to deliver a fix which basically boils down to not using the minimal.master.

So what’s the problem with minimal.master? Minimal.master is a cut down master page that is new to SharePoint 2010 and used by both Enterprise Search and Office Web Apps. As the Search master page it lacks a few key components available in the other SharePoint 2010 master pages. One fundamental component that is missing in minimal.master are navigation controls.

Minimal.master navigation

The minimal.master lacks most of the usual navigation controls you expect and need.

v4.master navigation

V4.master has the standard top navigation and the new 2010 breadcrumb (hidden inside the folder “up” icon)

Missing the main navigation leaves an Enterprise Search Centre completely isolated from the rest of your SharePoint solution. This is a big limitation – is there are any situation where you shouldn’t be able to get from your search results back to the main and/or other sites?

So why don’t we just change the search master page to one of those other fully featured ones like V4.master? Yeah that was my first idea too. And look what we get…

v4.master applied to search

An Enterprise Search Centre with v4.master applied “floats” the search controls into the breadcrumb navigation.

That wasn’t the result I was expecting and I guess it wasn’t the result most people were expecting if they tried this? This is not a bug but one of those “by design” problems. What you’re seeing is the way the four page layouts of Enterprise Search have been implemented to work specifically with the placeholders in the minimal.master master page. Personally I think this was a poor implementation decision because it uses some of the core placeholders completely differently than the other OOTB SharePoint master pages. Compare V4.master and minimal.master:

Place Holder Use in Minimal.master for search Use in V4.master for…most other things
TitleInBreadCrumb Search controls Breadcrumb navigation controls
SPNavigation Empty in the master page. The search page layouts add page editing controls and the ribbon instead. Page editing controls and the ribbon

The Current Approaches to using a Custom Master Page with Search

We have two options if we want to get rid of the minimal.master from search and put back some of the things we have lost:

  1. Create a custom search master page that is compatible with the search page layouts; or
  2. Modify the search page layouts to make them compatible with an existing custom master page

If you want to do the first option and create a custom master page for search then Randy Drisgill has a really useful and detailed post on how to convert a V4.master (normal) master page to work with the Search Centre.

The second alternative solution is to modify the page layouts to work with your existing custom master page. I first came across the idea via Chris O’Connor and prefer this approach. It’s biggest benefit is you only have to develop/test/maintain one master page which can be used on all your SharePoint sites including the search site!

Unfortunately there is at least one negative side effect to modifying the search page layouts – it makes them unghosted (customized). Unghosted files are generally frowned upon in SharePointland so this approach won’t always suit everyone’s environment/requirements. The biggest problem, and a very valid reason to dislike unghosted files, is once they are customized a copy lives in the content database that is disconnected from the original file system version. This means:

  • These page layouts will not be updated by any changes to the file system versions such as solution (wsp) upgrades and service packs
  • There is a performance penalty (I don’t know how much?) because of the extra database hit required to retrieve the page layout from the content database

Fix Option 2. Explained

There are a few changes that have to be made to all of the search page layouts and your custom master page to implement fix option number 2. To make this as clean as possible I have packaged the changes into a sandbox solution and use a site collection feature (feature activation receiver) to perform all of the heavy lifting in the page layouts:

  1. Change the target placeholder that is used by the search controls by replacing the Id from TitleInBreadCrumb to a custom placeholder ID CustomSearchControls
  2. Remove the SPNavigation placeholder and all its content from the page layouts. This content placeholder is in the v4 master page already so it’s just a duplicate and causes weird ribbon “jumping”
  3. Add some CSS style rules to hide the left navigation areas of the page because search doesn’t use this area of the page

A  big benefit of doing all that work in a feature receiver is the changes are all reverted and the page layouts are reghosted/uncustomized if the feature is deactivated.

Last point – there are changes that must be made to your custom master page to support these modified page layouts. If you don’t add the following placeholder you’ll get an error. The screen shot below shows what needs to be added (the wrapping <div> isn’t strictly necessary but it allows for any custom styling that might also be needed).

Custom PlaceHolder

And once you upload the sandbox solution to the solution gallery, activate the solution/feature and switch your master page to one with the custom placeholder this is what you will see:

Search with custom v4.master applied

This is a good place to stop. The files are up on codeplex and I hope to do a follow up post soon that explains the source code in detail. If you have any ideas on how to improve this or just general comments please hit me up via a blog comment or on twitter. For now here are links to the files:

  1. Sandbox solution with a site collection feature to do the page layout fix-up described in the post – Search.CustomMasterPageAdapter.wsp
  2. Source code of the feature receiver – PageLayoutFixup.cs
  3. Example custom master page which is just v4.master with the custom place holder added – Custom.v4.master

14 Comments so far
Leave a comment

[…] This post was mentioned on Twitter by Nick Hadlee, Donald Donais. Donald Donais said: RT @nickhadlee: An Alternative Method for Using Custom Master Pages with Search in SharePoint 2010: #SP2010 […]

Pingback by Tweets that mention An Alternative Method for Using Custom Master Pages with Search in SharePoint 2010 « Nick Hadlee's Blog on SharePoint and Other Occasional Rants… --

Good post and I will keep it saved. I only have one sort of touchy subject, and I really don’t know how to bring it up politely, so maybe I’ll whisper it…[You kept misspelling “center.” :o) ]

Comment by Jim

Thanks Jim – appreciate the feedback.

I’m trying to use “the Queens finest” but alas you are right the spelling should be Americanised/Americanized to align with how SharePoint spells things.

Comment by nickhadlee

One less thing to take care of on the long laundry list that grows by the day. Thanks for this!

I fully approve of your spelling of centre but SharePoint may like a ~/ in front of the _controltemplates references in your example master file! Otherwise this is a great start.

Comment by Neil Bailey

Installed it on
Had an activation error, something to do with content approval on library but it seems to have worked.
Nice solution…

Comment by Ian Morrish

Thanks Ian – glad to hear it was some help for wssdemo!

This is still WIP and requires a bit of cleanup so Id be keen to track down the cause of the error to make this a more robust solution.

Comment by nickhadlee

Hey Nick,

Great solution cause I was getting gray hears from trying to modify a custom master page for search while having project leaders in my neck who think it’s al just clicker de click.

Only now I stil have a problem. I deployed the sandbox solution to the gallery on the top level site and activated it. I can see it’s activated but when I go to my search center which was default on minimal.master I get a nice correlation ID error.

Any suggestions what might have gone wrong?
I double checked how my sandbox sollution service is setup and it must be ok.

Kind regards,

Comment by Maarten

Thanks Maarten,

Are you able to hunt down the error in the ULS logs via the correlation ID? If you are using an out-of-the-box master page (minimal.master or v4.aster) you will get an error as this solution is injecting a custom PlaceHolder in the page layouts and the OOTB master pages don’t have this PlaceHolder. Have you created a custom master page (or copied the example one) that has the required PlaceHolder?

Another thing I know that does fail at the moment is activating this solution on a basic search center instead of an enterprise search center (The two work a bit differently and I intend to try and fix the problem).

Hope that helps!

Comment by nickhadlee

Hi Nick,

Thanks for your reply. I did some extra research like you suggested but no succes yet. Below you find what I found in my logs maybe it helps.

What I’ve done: I created a site collection from central admin and from the top level site in the settings >> Site management I created a new site (sub site) for the Search Center. I used the Enterprise Search Center Template in combination with a Dutch language Pack.

After I deployed the Sandbox solution I activated it and then on the Top Level Site I checked if it was activated. Then in the Search Center I got the error below. I made sure the Search Center is using the minimal.master before activating but also if I choose the v4 the result is the same (both are OOTB).

I hope you can help, thanks in advanced,

Er is een onverwachte fout opgetreden.
Problemen met Microsoft SharePoint Foundation oplossen.
Correlatie-id: 1022c091-ba05-4f21-93cf-5e56ebaaa9e3
Datum en tijd: 20-1-2011 9:03:58

I get 7 lines I exported it to a *.csv and try to paste to make it a bit less like spagetie.

01-20-2011 09:03:58.36
w3wp.exe (0x2B98)
0x22C4 SharePoint Foundation
Logging Correlation Data xmnv
Medium Name=Request (GET:http://hisinfo:80/zoekcentrum/Paginas/default.aspx)

01-20-2011 09:03:58.37
w3wp.exe (0x2B98)
0x22C4 SharePoint Foundation
Logging Correlation Data xmnv
Medium Site=/ 1022c091-ba05-4f21-93cf-5e56ebaaa9e3

01-20-2011 09:03:58.37
w3wp.exe (0x2B98)
0x22C4 SharePoint Foundation Monitoring b4ly
High Leaving Monitored Scope (PostResolveRequestCacheHandler).
Execution Time=14,2071129151889 1022c091-ba05-4f21-93cf-5e56ebaaa9e3

01-20-2011 09:03:58.45
w3wp.exe (0x2B98)
0x22C4 SharePoint Foundation Monitoring b4ly
High Leaving Monitored Scope (GetFileAndMetaInfo).
Execution Time=68.944796056482 1022c091-ba05-4f21-93cf-5e56ebaaa9e3

01-20-2011 09:03:58.45
w3wp.exe (0x2B98)
0x22C4 SharePoint Foundation Monitoring b4ly
High Leaving Monitored Scope (GetWebPartPageContent).
Execution Time=69.1534817972675 1022c091-ba05-4f21-93cf-5e56ebaaa9e3

01-20-2011 09:03:58.52
w3wp.exe (0x2B98)
0x22C4 SharePoint Foundation Runtime tkau Unexpected System.Web.HttpException: Cannot find ContentPlaceHolder ‘PlaceHolderSearchControls’ in the master page ‘/_catalogs/masterpage/minimal.master’, verify content control’s ContentPlaceHolderID attribute in the content page. at System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection) at System.Web.UI.Page.get_Master() at System.Web.UI.Page.ApplyMasterPage() at System.Web.UI.Page.PerformPreInit() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 1022c091-ba05-4f21-93cf-5e56ebaaa9e3

01-20-2011 09:03:58.53
w3wp.exe (0x2B98)
0x22C4 SharePoint Foundation Monitoring b4ly
Medium Leaving Monitored Scope (Request (GET:http://hisinfo:80/zoekcentrum/Paginas/default.aspx)).
Execution Time=171,262828096867 1022c091-ba05-4f21-93cf-5e56ebaaa9e3

Comment by Maarten

The OOTB master pages wont work with the adapters at the moment.

I suggest you have a look at this example master page. Its the V4.master with the extra custom search PlaceHolder added. Try uploading that master page to your gallery and use this master page before activating the feature.

Comment by nickhadlee

😉 Hey Nick,

I solved it 🙂 I completly overlooked the part where I needed to customize the v4.master.

I made a copy of the original v4.master and called it v4_search.master I inserted your code just after.

And then I cativated the feature again and was really happy.

Thanks for your help en next time I will read more carefully.

Kind regards,

Comment by Maarten

Hi! I really like the idea but I can’t make it work for a FAST Search Center. Any idea of how I can use the codeplex wsp feature without a deployment error (’cause is different from the targeted enterprise search site)? Thanks!

Comment by danielafv

Hi Daniel, I’ve begun a response on the CodePlex discussion you started relating to this.

Comment by nickhadlee

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: