I am developing a branding project, in this project i have custom master page, i can successfully deploy it and automatically apply to the root web. But i want all the subsites inherit the master page programmatically(From feature event receiver)
But the;
rootWeb.AllProperties["__InheritsCustomMasterUrl"] = "True";
is not working. My master page is not being applied to the subsites. Do you have any ideas why?
Edit: Here is my full code. It still doesnt work
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
var site = properties.Feature.Parent as SPSite;
if (site != null)
{
SPWeb rootWeb = site.RootWeb;
string serverRelativeUrl = rootWeb.ServerRelativeUrl;
if (!String.Equals(serverRelativeUrl, ForwardSlash, StringComparison.OrdinalIgnoreCase))
serverRelativeUrl += ForwardSlash;
string customMasterUrl = serverRelativeUrl + "_catalogs/masterpage/" + DefaultMasterPage;
bool update = false;
if (!String.Equals(rootWeb.CustomMasterUrl, customMasterUrl, StringComparison.OrdinalIgnoreCase))
{
rootWeb.CustomMasterUrl = customMasterUrl;
rootWeb.AllProperties["__InheritsCustomMasterUrl"] = "True";
update = true;
}
if (update)
rootWeb.Update();
string customSearchMasterUrl = serverRelativeUrl + "_catalogs/masterpage/" + SearchMasterPage;
foreach (SPWeb web in site.AllWebs)
{
if (web.WebTemplate == "SRCHCENTERLITE" || web.WebTemplate == "SRCHCEN" || web.WebTemplate == "SRCHCENTERFAST")
{
if (!String.Equals(web.CustomMasterUrl, customSearchMasterUrl, StringComparison.OrdinalIgnoreCase))
{
web.CustomMasterUrl = customSearchMasterUrl;
web.Update();
}
}
else
{
web.AllProperties["__InheritsCustomMasterUrl"] = "True";
web.Update();
}
}
}
}