I've created and deployed a custom master page and kept its scope to be Web because I want to apply to specific sites not the complete site collection. But when I activate feature at a specific site, it automatically gets activated to the parent site and thus each site. This happens only the first time a feature is activated after deploying. There after( After I've manually deactivated that feature from the parent site) it works fine. Please can anyone suggest something so that it gets activated on the specific site only? It's been chewing off my mind for quite sometime now :/
Following is the code I've used on Feature activated method of feature event receiver
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
using (var web = (SPWeb)properties.Feature.Parent)
{
string customUrltoUse = web.ServerRelativeUrl + CustomizedMasterUrl;
customUrltoUse = customUrltoUse.Replace("//", "/");
// Store the old Master URL's and Custom Master URL's
web.AllProperties["OldMasterUrl"] = web.MasterUrl;
web.AllProperties["OldCustomMasterUrl"] = web.CustomMasterUrl;
web.AllProperties["__InheritsCustomMasterUrl"] = "False";
web.AllProperties["__InheritsMasterUrl"] = "False";
// Assign the Master URL to both properties
try
{
if (web.IsRootWeb)
{
foreach (SPWeb subweb in web.Webs)
{
if (subweb.WebTemplateId != 50 && subweb.WebTemplateId != 14483)
{
subweb.MasterUrl = customUrltoUse;
subweb.CustomMasterUrl = customUrltoUse;
subweb.Update();
if (subweb.Webs.Count > 0)
{
foreach (SPWeb subsubweb in subweb.Webs)
{
subsubweb.MasterUrl = customUrltoUse;
subsubweb.CustomMasterUrl = customUrltoUse;
subsubweb.Update();
}
}
}
}
}
//SPFile uipmasterPage = web.GetFile(web.ServerRelativeUrl + "/_catalogs/masterpage/uipcustom.master");
//uipmasterPage.Delete();
}
catch
{
}
web.MasterUrl = customUrltoUse;
web.CustomMasterUrl = customUrltoUse;
web.Update(); }
}