I applicate the master page to the parent site and to all my subsites. In fact the master page was not applicated to all the subsite. this is the hierarchy:

-parent site: type publishing  -sub site1: wikisite
                               -subsite 2:team site 
                               -subsite 3: publishing

I only found the subsite 3 have the same master page as parent site? So is teher a solution how to force all the subsite to take the parent's master page

1 Answer 1


There is. Either by C#:

var web = SPContext.Current.Web; //you can get that in a different way
var rootWeb = web.Site.RootWeb; //You root web site
web.MasterUrl = rootWeb.MasterUrl;
web.CustomMasterUrl = rootWeb.CustomMasterUrl;

or by PowerShell:

$web = Get-SPWeb http://wikisiteURL
$rootWeb = Get-SPWeb http://parentsiteURL
$web.MasterUrl = $rootWeb.MasterUrl;
$web.CustomMasterUrl = $root.CustomMasterUrl;

Throw in a for-each for web.Site.AllWebs and you will be able to do that for all the subsites. Don't forget to properly dispose of the SPWeb objects as well.

  • $rootWeb = Get-SPWeb $web.ParentWeb.Url a have erroe on this , and $rootWeb.MasterUrl= give the seattle
    – Imen Turki
    Mar 4, 2016 at 10:50
  • Use this instead: $rootWeb = Get-SPWeb $web.Site.RootWeb; and then $rootWeb.MasterUrl should display your custom master page. Mar 4, 2016 at 11:04
  • Sorry, I mistyped a bit of code. This is how it needs to look like: $rootWeb = $web.Site.RootWeb; Your code should work. Does it give any error? Mar 4, 2016 at 11:34
  • know ok , it works fine
    – Imen Turki
    Mar 4, 2016 at 13:19

Your Answer

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

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