【问题标题】:Refresh masterpage for subsites when applying a new one to root web将新主页应用于根网站时刷新子网站的主页
【发布时间】:2011-09-18 13:33:06
【问题描述】:

让我公开我的问题: 我有一个根站点、一个母版页和许多子站点。有些正在使用根站点母版页(通过继承),有些没有使用根站点母版页。

当我使用这样的功能事件接收器更新根站点 MP 时:

SPWeb w = ((SPSite)properties.Feature.Parent).OpenWeb();
Uri masterUri = new Uri(w.Url + "/_catalogs/masterpage/AdventureWorks.master");
//MasterPage used by publishing pages
w.CustomMasterUrl = masterUri.AbsolutePath;
w.AllowUnsafeUpdates = true;
w.Update();

...母版页是为根站点更新的,但不是为从根站点母版页继承的子站点更新的!当我转到子站点的站点母版页设置页面时,“从该站点的父级继承站点母版页”单选按钮已选中。

当我从“站点母版页设置”页面应用新的 MasterPage 时,我没有遇到这个问题。

有关信息:我在一个发布站点中的根站点以及“SharePoint Server Publishing Infrastructure”和“SharePoint Server Publishing”功能正在运行。

我错过了什么吗?

【问题讨论】:

    标签: c# sharepoint-2010 master-pages


    【解决方案1】:

    一个月后仍然没有回复:/ 所以我想没有机制来更新子网站的所有母版页。 所以我更新了这样的功能激活事件接收器:

    using (SPWeb w = ((SPSite)properties.Feature.Parent).OpenWeb())
            {
                Uri masterUri = new Uri(w.Url + "/_catalogs/masterpage/AdventureWorks.master");
                w.CustomMasterUrl = masterUri.AbsolutePath;
                w.AllowUnsafeUpdates = true;
                w.Update();
    
                foreach (SPWeb ww in w.Site.AllWebs)
                {
                    if (!ww.IsRootWeb)
                    {
                        Hashtable hash = ww.AllProperties;
                        if (string.Compare(hash["__InheritsCustomMasterUrl"].ToString(), "True", true) == 0)
                        {
                            ww.CustomMasterUrl = masterUri.AbsolutePath;
                            ww.AllowUnsafeUpdates = true;
                            ww.Update();
                        }
                    }
                }
            }
    

    目标是测试每个子网站是否继承 masterPage(或不继承)。如果是这样,我们必须更新 CustomMasterUrl 属性。

    【讨论】:

      【解决方案2】:

      使用它在根和所有子网站上设置母版页:

              var web = site.RootWeb;
      
              web.MasterUrl = web.CustomMasterUrl = SPUtility.ConcatUrls(web.ServerRelativeUrl, "_catalogs/mymaster.master");
              web.Update();
      
              foreach (SPWeb subWeb in site.AllWebs)
              {
                  using (subWeb)
                  {
                      if (subWeb.IsRootWeb) continue;
      
                      var hash = subWeb.AllProperties;
      
                      subWeb.MasterUrl = subWeb.CustomMasterUrl = web.MasterUrl;
      
                      hash["__InheritsMasterUrl"] = "True";
                      hash["__InheritsCustomMasterUrl"] = "True";
      
                      subWeb.Update();
                  }
              }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-11-15
        • 1970-01-01
        • 2012-11-14
        • 1970-01-01
        • 2013-07-28
        • 1970-01-01
        • 2011-02-15
        相关资源
        最近更新 更多