1

I need to create a custom home page for our SharePoint 2010 site. The rest of the site will use a separate template for all of the sub-pages.

Should I create a dedicated master page for the home page on its own? Also, what is the ideal way to apply this against the site? I have a lot of sub-sites, so does this mean I will have to set the home page master page to be the parent level item and then go change/update all of the sub-sites to use the other (sub-site) master page?

2
  • Do you want to do this with code, as rjcup3 outlines? Or do you want the out of the box, SharePoint Designer approach?
    – teylyn
    Feb 26, 2013 at 9:43
  • it would be nice to compare and contrast both approaches :)
    – Dkong
    Feb 26, 2013 at 16:55

1 Answer 1

2

You can set a custom page as the landing / home page of your site by setting the relative URL of the page to the WelcomePage property of the root folder of the root web. Like:

using (SPSite site = new SPSite("http://server:port/")) 
{
    SPWeb web = site.RootWeb;
    SPFolder rootFolder = web.RootFolder;
    rootFolder.WelcomePage = "Pages/YourCustomHomePage.aspx";
    rootFolder.Update();
}

If a user navigates to http://server:port/ they would be served http://server:port/Pages/YourCustomHomePage.aspx.

Whether or not you make a master page just for the home page depends on the design. If it's a different layout, with different branding, and a different structure you not only should make a separate master page, you probably must do so. You can always set the master page in the markup of your custom home page and leave the master page for the rest of your site (set at SPWeb.MasterUrl or SPWeb.CustomMasterUrl) alone.

One alternative to using a library within SharePoint to store the home page, is to use an application page in a folder under TEMPLATE\LAYOUTS instead. To do that requires you to set up a redirect page as explained in Redirect default.aspx or change default landing to page in _layouts folder?.

One reason for you to use an application page is if you need to use custom code behind as part of the requirements you have.

2
  • Thanks rjcup3. The home page will still be a different layout. It will be fixed width and the rest of the site will be full width. It will also require most of the usual Sharepoint features and functionality, ie login, search etc. The code you provided, where (which file) would that go in? If I'm understanding correctly one of your other suggestions is to make them all the same master page by default (ie to make the homepage and subsites inherit from the same master page) and then to detect/set the home to a different master page? This approach sounds good too.
    – Dkong
    Feb 26, 2013 at 16:59
  • I'd set all but the home page to use the standard master, and use a different master for the home page. You can set the master for the home page in the markup of the ASPX of your home page. The code sample I provided can go in an event receiver on your feature, or you can convert it to run in PowerShell if you'd prefer to manage it manually. You can also handle the feature's deactivation in an event receiver and set the welcome page back to default.aspx if you turn off the feature. Feb 26, 2013 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.