Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
    
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 '13 at 9:43
    
it would be nice to compare and contrast both approaches :) –  Dkong Feb 26 '13 at 16:55
add comment

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
    
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 '13 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. –  RJ Cuthbertson Feb 26 '13 at 17:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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