MOSS自定义母版页
自动化的 SharePoint 站点标记
Ted Pattison
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
自从我开始使用 SharePoint® 技术起,就经常会听到一个请求。公司总是希望创建独特的站点,而不是使用标准 SharePoint 站点。无论您使用 SharePoint 技术创建面向 Internet 的公司网站,还是创建拥有众多团队协作站点的 Intranet 环境,都可能会需要管理 SharePoint 站点的可视元素,例如,页面布局以及字体和颜色的使用等。
Windows® SharePoint Services (WSS) 3.0 通过主题提供标记。用户可以通过将 WSS 主题应用到站点来更改其外观。请注意,WSS 中的主题与 ASP.NET 中的完全不同。WSS 通过将级联样式表 (CSS) 文件从 Web 服务器的文件系统复制到当前站点的上下文并动态从各个页面链接到此 CSS 文件,来为主题实现其基础结构。
WSS 主题有一些限制,使得开发人员对其兴趣大减。第一个限制是 WSS 主题无法通过集成自定义母版页来自定义站点内使用的页面布局。而且,WSS 主题只能基于每个站点应用,而不能跨站点集合应用。不支持一次性将主题应用到站点集合中的所有站点。必须分别转到各个站点并应用同一主题,以保持整个站点集合在外观和功能上的一致性。
SharePoint Designer 为在 WSS 或 Microsoft® Office SharePoint Server (MOSS) 2007 中标记站点提供了另一种方法。您可以使用 SharePoint Designer 自定义站点的母版页并编辑和集成自定义 CSS 文件。但是,处理基于标准 WSS 站点的站点集合时,SharePoint Designer 未能提供一种方法来同步站点集合的所有站点以使用同一版本的自定义母版页。这可能会导致不得不跨多个母版页文件来复制和粘贴您的母版页剪辑。
如果将 SharePoint Designer 与 MOSS 配合使用情况会好一些,因为 MOSS 通过使用发布门户提供了 Web 内容管理 (WCM) 基础结构。MOSS 发布门户是一个站点集合,其中包含的发布站点可以自动同步所有站点的页面以使用相同的母版页和相同的 CSS 文件。
但务必要记住,使用 SharePoint Designer 创建适用于跨多个站点集合或用于企业方案的标记解决方案时,有一些需要注意的限制。请记住,使用 SharePoint Designer 所做的更改在特定站点的上下文中始终被作为一次性自定义内容。这意味着,使用 SharePoint Designer 进行自定义可能需要一些技巧,或可能无法在站点集合之间或场之间进行迁移。此外,将使用 SharePoint Designer 进行的站点自定义集成到源代码管理系统(如 Visual Studio® Team System)中是一件不切合实际的事情。
本月,我将介绍如何为 SharePoint 站点开发自定义标记解决方案,此解决方案将利用 WSS 的功能在站点集合级别集成自定义母版页和自定义 CSS 文件。我将会对一个名为 LitwareBranding 的示例标记解决方案中的代码加以说明,此解决方案是使用 Visual Studio 项目进行开发并使用解决方案包进行部署的。您可以在本期的代码下载中找到全部代码。
采用 Visual Studio 和生成解决方案包这两个因素使得将标记解决方案部署到运行 WSS 3.0 或 MOSS 2007 的任何场中均成为可能。这也使得为每个母版页和 CSS 文件(此文件可以在多个站点集合或场中重复使用)创建单个源文件变得更加容易。此外,与使用 SharePoint Designer 相比,Visual Studio 方法可能更具吸引力,因为它允许将所有源文件签入到源代码管理系统中。您还可以更轻松地将工作从开发场转移到过渡场进行测试,然后投入生产。
LitwareBranding 解决方案简介
本月专栏附带了一个名为 LitwareBranding 的示例 Visual Studio 项目。图 1 显示了 Visual Studio 中 LitwareBranding 项目的结构。正如您所看到的,该解决方案使用了三种不同的功能设计而成,在本月专栏中我将利用整个篇幅对其用途和实现加以说明。此解决方案中的核心功能被命名为 LitwareBranding,它被设计为由 WSS 或 MOSS 站点集合范围内的用户激活。LitwareBranding 功能的激活将强制 LitwareBranding 解决方案应用本月专栏中将要介绍的所有标记技术。
![](http://i.msdn.microsoft.com/cc700347.fig01(zh-cn).gif)
图 1 Visual Studio 中的 LitwareBranding 解决方案
下面我们开始代码演练,首先查看被命名为 LitwareBranding 的核心功能所对应的 feature.xml 文件,如图 2 所示。LitwareBranding 功能是使用 Site 的 Scope 属性值定义的,这意味着它已被限制在站点集合级别。这种构思的出发点是站点集合所有者应该能够激活单个功能,以将 Litware 公司标记应用到当前站点集合内的所有站点。
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
<Feature Id="065E2243-B968-4F14-BAAE-610BB975EFB7" Title="A sample feature: LitwareBranding" Description="Demoware created for Ted Pattison's OfficeSpace column" Hidden="FALSE" Scope="Site" ImageUrl="LitwareBranding\AfricanPith32.gif" ReceiverAssembly="LitwareBranding, [4-part assembly name]" ReceiverClass="LitwareBranding.FeatureReceiver" xmlns="http://schemas.microsoft.com/sharepoint/"> <ElementManifests> <ElementManifest Location="elements.xml"/> <ElementManifest Location="stapling.xml" /> <ElementFile Location="LitwareBranding.master"/> </ElementManifests> </Feature>
LitwareBranding 功能包含一个名为 LitwareBranding.master 的母版页模板和一个名为 elements.xml 的元素清单。elements.xml 清单内包含声明性的 XML 置备逻辑,可用于创建此母版页模板的实例。这一逻辑由带有内部 File 元素的 Module 元素定义:
<Module Name="MasterPages" Path="" List="116" Url="_catalogs/masterpage" > <File Url="LitwareBranding.master" Type="GhostableInLibrary" /> </Module>
在功能激活期间,此 Module 元素会强制 WSS 在顶级站点的母版页库中置备一个名为 LitwareBranding.master 的母版页模板的实例。此母版页实例置备完毕后,便可以提供针对 WSS 对象模型编程的代码,以同步站点集合内链接到此母版页的页面,对此我将在下一部分加以介绍。
为品牌管理创建实用程序类
LitwareBranding 项目包含一个名为 BrandManager 的类。此实用程序类封装了针对 WSS 对象模型编程的所有代码,可应用和删除各种标记元素。BrandManager 类提供了一些静态方法,可完成以下任务:
- 同步链接到 LitwareBranding.master 的站点页面
- 同步使用备选 CSS 文件的页面
- 同步使用自定义图形作为站点徽标的页面
- 添加对换出应用程序页面的母版页的支持
在深入了解具体成员之前,请先看一下图 3,其中显示了 BrandManager 类的所有成员。该类包含多个静态属性,用于解析指向各种资源(如母版页和 CSS 文件)的 URL。例如,SiteCollectionUrl 属性可返回 Web 应用程序相对于当前站点集合的路径。DefaultMasterPageUrl 可返回 Web 应用程序相对于名为 default.master 的默认母版页的路径,此默认母版位于当前站点集合的顶级站点的母版页库中。此路径可使用 SiteCollectionUrl 属性以及下列站点相对路径进行解析:
_catalogs/masterpage/default.master
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
public class BrandManager { // read-only properties public static string SiteCollectionUrl public static string DefaultMasterPageUrl public static string CustomMasterPageUrl public static string CustomCssUrl public static string CustomSiteLogoUrl // utility branding methods public static void ConfigureMasterUrl(bool ApplyMasterUrl) {} public static void ConfigureCustomMasterUrl(bool ApplyCustomMasterUrl) {} public static void ConfigureAlternateCss(bool ApplyCustomCss) {} public static void ConfigureSiteLogo(bool ApplySiteLogo) {} public static void ConfigureApplicationPageMaster(bool ApplyApplicationPageMaster) {} }
CustomMasterPageUrl 属性可返回 Web 应用程序相对于名为 LitwareBranding.master 母版页实例的路径,此实例位于当前站点集合的顶级站点的母版页库中。此路径可使用 SiteCollectionUrl 属性以及下列站点相对路径进行解析:
_catalogs/masterpage/litwarebranding.master
现在,让我们研究一下 ConfigureMasterUrl 方法,它会枚举当前站点集合内的每个站点并会更新各站点的 MasterUrl 属性以指向自定义母版页或默认母版页:
public static void ConfigureMasterUrl(bool ApplyMasterUrl) { // determine MasterUrl property setting string MasterUrlPath = (ApplyMasterUrl ? CustomMasterPageUrl : DefaultMasterPageUrl); // update MasterUrl property for all sites foreach (SPWeb site in SPContext.Current.Site.AllWebs) { site.MasterUrl = MasterUrlPath; site.Update(); } }
请注意,MasterUrl 属性会影响使用 ~masterurl\default.master 的 MasterPageFile 属性设置所创建的所有站点页面。其中包括标准 default.aspx 页面模板,它为许多 SharePoint 站点模板(包括工作组网站和空白网站)提供主页。还包含标准 WSS 列表类型所使用的窗体页面(如 AllItems.aspx 和 NewItem.aspx)。
当您更新 MasterUrl 属性时,MOSS 发布站点中的页面布局不会受到影响这包括 MOSS 发布站点的页面库中的所有内容页面。
相反,这些内容页面会对 MastePageFile 属性使用 ~masterurl\custom.master 形式的动态令牌。此令牌不同于 ~masterurl\custom.master 令牌,因为它是使用 CustomMasterUrl 属性而非 MasterUrl 属性切换出的。因此,BrandManager 类提供了另一个名为 ConfigureCustomMasterUrl 的方法,可用于切换出在 MOSS 发布站点的页面库中创建的内容页面的母版页。
public static void ConfigureCustomMasterUrl( bool ApplyCustomMasterUrl) { // determine MasterUrl property setting string CustomMasterUrlPath = (ApplyCustomMasterUrl ? CustomMasterPageUrl : DefaultMasterPageUrl); // update MasterUrl property for all sites foreach (SPWeb site in SPContext.Current.Site.AllWebs) { site.CustomMasterUrl = CustomMasterUrlPath; site.Update(); } }
除了换出母版页之外,LitwareBranding 解决方案还集成了一个名为 styles.css 的自定义 CSS 文件。LitwareBranding 解决方案采用的策略是将名为 styles.css 的 CSS 文件部署到 LAYOUTS 目录内部所嵌套的目录中,以便能够将其一次性部署到每个前端 Web 服务器的文件系统中。在 LAYOUTS 目录内进行部署的优点在于 style.css 之类的文件可以一次性部署到 Web 服务器的文件系统中,而且仍可使用 CustomCssUrl 属性所返回的标准 URL 从当前场内的任何站点进行访问:
public static string CustomCssUrl { get { return "/_layouts/1033/STYLES/LitwareBranding/styles.css"; } }
BrandManager 类提供了一个名为 ConfigureAlternateCss 的方法,它使用 CustomCssUrl 属性将 URL 分配给当前站点集合内各站点的 AlternateCSS 属性:
public static void ConfigureAlternateCss(bool ApplyCustomCss) { // determine MasterUrl property setting string AlternateCssUrl = (ApplyCustomCss ? CustomCssUrl : string.Empty); // update AlternateCssUrl for all sites foreach (SPWeb site in SPContext.Current.Site.AllWebs) { // make sure no theme is enabled site.ApplyTheme(string.Empty); // apply custom CSS file site.AlternateCssUrl = AlternateCssUrl; site.Update(); } }
WSS 中内置的标记功能还提供了一种更换显示在页面左上角的标准 WSS 站点徽标的简单方法。LitwareBranding 解决方案通过包括名为 SiteLogo.gif 的自定义图形文件(被部署在 IMAGES 目录内嵌套的目录中)来运用此功能。与名为 styles.css 的 CSS 文件一样,图形文件 SiteLogo.gif 也是通过这种方式部署的,并且可以使用 CustomSiteLogoUrl 属性所返回的 URL 从当前场内的任何站点进行访问:
public static string CustomSiteLogoUrl { get { return "/_layouts/images/LitwareBranding/SiteLogo.gif"; } }
BrandManager 类的 ConfigureSiteLogo 方法被编写为枚举当前站点集合的所有站点并更新 SiteLogoUrl 属性:
public static void ConfigureSiteLogo(bool ApplySiteLogo) { // determine SiteLogoUrl property setting string SiteLogoUrl = (ApplySiteLogo ? CustomSiteLogoUrl : string.Empty); // update AlternateCssUrl for all sites foreach (SPWeb site in SPContext.Current.Site.AllWebs) { site.SiteLogoUrl = SiteLogoUrl; site.Update(); } }
换出母版页
虽然 SharePoint 可使换出站点页面的母版页相对容易一些,但它并没有为换出在 LAYOUTS 目录外运行的内嵌式应用程序页面(如标准 WSS 站点设置页面 settings.aspx)的母版页提供一种直观的方式。这些应用程序页面均被链接到 WSS 在 LAYOUTS 目录内部署的名为 application.master 的标准 WSS 母版页。但是,如果要创建的是可以换出站点集合内所有站点页面的母版页的标记解决方案,则您可能希望通过换出应用程序页面(如 settings.aspx)的母版页来使其可以使用自定义母版页,从而创建一致的外观。
LitwareBranding 解决方案演示了如何换出链接到标准母版页文件 application.master 的所有应用程序页面的母版页。在用于换出母版页的技术中包括了如何实现自定义 HttpModule,它将在名为 PreInit 的 ASP.NET 页面生命周期中为其中一个事件注册一个事件处理程序。此事件是当您希望在初始化页面请求的处理过程中换出母版页时,ASP.NET 编程模型要求您执行的事件。
类 LitwareBrandingHttpModule 将提供在 LitwareBranding 解决方案中用来换出母版页的 HttpModule(请参见图 4)。此 HttpModule 类会为 Init 方法中的 PreRequestHandlerExecute 事件注册一个处理程序。在 PreRequestHandlerExecute 事件处理程序的方法实现过程中,HttpModule 类可决定请求是否基于从 ASP.NET Page 类派生而来的 HttpHandler 对象。只有当请求基于 Page 派生的对象时,HttpModule 类才会从 PreInit 事件注册事件处理程序。PreRequestHandlerExecute 事件处理程序中的代码还会执行检查以确保传入请求以 _layouts 目录内的页面作为目标,在处理 WSS 中的应用程序页面时始终都遵循此原则。
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
using System; using System.Web; using System.Web.UI; using Microsoft.SharePoint; namespace LitwareBranding { public class LitwareBrandingHttpModule : IHttpModule { public void Init(HttpApplication context) { context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute); } void context_PreRequestHandlerExecute(object sender, EventArgs e) { Page page = HttpContext.Current.CurrentHandler as Page; if (page != null) { // register handler for PreInit event page.PreInit += new EventHandler(page_PreInit); } } void page_PreInit(object sender, EventArgs e) { // IF – requested page links to application.master // THEN – dynamically modify page to link to custom .master file } public void Dispose() { /* empty implementation */ } } }
请切记,HttpModule 不能部署在单个站点集合的 WSS 场中。相反,必须按照全有或全无的主张在 Web 应用程序级别配置 HttpModule。但是,Web 应用程序可能包含成百上千个站点集合,可能只有某些站点集合已启用了 LitwareBranding 功能。因此,HttpModule 类的 PreInit 事件处理程序必须能够确定当前站点集合是否配置了为其应用程序页面换出母版页的行为。
通过在站点集合的顶级站点中创建自定义属性来指明是否应启用换出应用程序页面的母版页这一功能,LitwareBranding 解决方案成功解决了此问题。查看在 BrandManager 类中定义的 ConfigureApplicationPageMaster 方法的实现过程:
public static void ConfigureApplicationPageMaster( bool ApplyApplicationPageMaster) { SPWeb TopLevelSite = SPContext.Current.Site.RootWeb; if (ApplyApplicationPageMaster) { TopLevelSite.Properties["UseCustomApplicationPageMaster"] = "True"; } else { TopLevelSite.Properties["UseCustomApplicationPageMaster"] = "False"; } TopLevelSite.Properties.Update(); }
此方法在顶级站点中创建了一个名为 UseCustomApplicationPageMaster 的自定义属性并为其分配了值 True。现在,HttpModule 中的 PreInit 事件处理程序的方法实现可以在当前站点集合内查找此属性,以了解它是否已被配置为允许换出应用程序页面母版页。请注意,PreInit 事件处理程序还会执行多项其他检查,以确定在当前请求上下文中是否适合换出母版页(请参见图 5)。
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
void page_PreInit(object sender, EventArgs e) { Page page = sender as Page; if ((page != null) && (page.MasterPageFile != null) && (page.Request.Url.AbsolutePath.Contains("_layouts")) && (SPContext.Current != null) ) { // inspect UseCustomApplicationPageMaster property SPWeb site = SPContext.Current.Site.RootWeb; string UseCustomApplicationPageMaster = site.Properties["UseCustomApplicationPageMaster"]; if ((!string.IsNullOrEmpty(UseCustomApplicationPageMaster)) && (UseCustomApplicationPageMaster.Equals("True"))) { // now replace application.master with customized version if (page.MasterPageFile.Contains("application.master")) { page.MasterPageFile = "/_layouts/LitwareBranding/application.master"; } } } }
当 PreInit 事件处理程序确定当前站点集合已被配置为允许换出应用程序页面的母版页并且当前页面已链接到 application.master 后,它会修改当前 ASP.NET Page 对象的 MasterPageFile 属性,以使用 LAYOUTS 目录下特定解决方案目录中的自定义母版页,目录路径如下:
/_layouts/LitwareBranding/application.master
在 Web.config 文件中注册 HttpModule
使用 WSS 和 MOSS 部署业务解决方案时,最好在解决方案包中分配您的开发工作。例如,Visual Studio 项目 LitwareBranding 构建了一个名为 LitwareBranding.wsp 的单一解决方案包,利用它可以简单可靠地将此解决方案部署到运行 WSS 3.0 或 MOSS 2007 的任何场中。但是,LitwareBranding 解决方案需要将 HttpModule 条目添加到各 Web 应用程序的 web.config 文件中,而此应用程序将运行在激活了 LitwareBranding 功能的站点集合中。
为更新特定 Web 应用程序内的 web.config 文件,LitwareBranding 解决方案使用了名为 LitwareBrandingWebApplication 的第二个功能。此功能仅在 Web 应用程序级别有效并且还配置了一个功能接收器类,当此功能在特定 Web 应用程序范围内激活和停用时会触发事件处理程序:
<Feature Id="FF739C76-0B08-4bc2-A3A2-F61524B492D8" Title="Litware Branding Support Feature (WebApplication)" Scope="WebApplication" Hidden="False" ReceiverClass="LitwareBranding. FeatureReceiverWebApplication" ReceiverAssembly="LitwareBranding, [4-part assembly name]" xmlns="http://schemas.microsoft.com/sharepoint/"> <!-- no declarative elements --> <ElementManifests /> </Feature>
与任何其他功能接收器类一样,FeatureReceiverWebApplication 类继承自 SPFeatureReceiver 类,并取代了名为 FeatureInstalled、FeatureActivated、FeatureDecactivating 和 FeatureUninstalling 的四个处理程序方法。FeatureActivated 的实现将 HttpModule 条目添加到当前 Web 应用程序的 web.config 文件中。FeatureDeactivating 的实现可通过删除 HttpModule 条目来反转该操作。
如果您需要将某个条目添加到 web.config 文件中,最好使用 WSS 对象模型中的 SPWebConfigModification 类。FeatureReceiverWebApplication 类包含一个名为 CreateHttpModuleModification 的实用程序方法,用于创建和初始化 SPWebConfigModification 的实例,然后将其以返回值的形式传回(请参见图 6)。
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
public SPWebConfigModification CreateHttpModuleModification() { SPWebConfigModification modification; string ModName = "add[@name='LitwareBrandingModule']"; string ModXPath = "configuration/system.web/httpModules"; modification = new SPWebConfigModification(ModName, ModXPath); modification.Owner = "LitwareBranding"; modification.Sequence = 0; modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode; modification.Value = @"<add name=""LitwareBrandingModule"" " + @ "type=" "LitwareBranding.LitwareBrandingHttpModule, [4-part assembly name]" " />"; return modification; }
当您有了可以返回初始化的 SPWebConfigModification 对象的实用程序方法(如 CreateHttpModuleModification)后,即可简单地从事件处理程序(如 FeatureActivated 和 FeatureDeactivating)调用此方法将所需的 HttpModule 条目添加到当前 Web 应用程序的 web.config 文件中或从中删除该条目(请参见图 7)。
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
public override void FeatureActivated( SPFeatureReceiverProperties properties) { SPWebApplication WebApp = (SPWebApplication)properties.Feature.Parent; WebApp.WebConfigModifications.Add( CreateHttpModuleModification()); WebApp.WebService.ApplyWebConfigModifications(); WebApp.WebService.Update(); } public override void FeatureDeactivating( SPFeatureReceiverProperties properties) { SPWebApplication WebApp = (SPWebApplication)properties.Feature.Parent; WebApp.WebConfigModifications.Remove( CreateHttpModuleModification()); WebApp.WebService.ApplyWebConfigModifications(); WebApp.WebService.Update(); }
在功能激活期间初始化标记
现在是将所有片段组合到一起的时候了。用户在指定站点集合内激活 LitwareBranding 功能后,会出现一个功能接收器以及 FeatureActivated 事件处理程序,它将使用 BrandManager 类来应用各种标记元素。此外还有一个 FeatureDeactivating 事件处理程序,可在功能禁用期间移除所有标记元素(请参见图 8)。
![](http://i.msdn.microsoft.com/Global/Images/clear.gif)
public override void FeatureActivated(SPFeatureReceiverProperties properties) { EnsureWebApplicationFeatureEnabled(); BrandManager.ConfigureMasterUrl(true); BrandManager.ConfigureCustomMasterUrl(true); BrandManager.ConfigureAlternateCss(true); BrandManager.ConfigureSiteLogo(true); BrandManager.ConfigureApplicationPageMaster(true); } public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { BrandManager.ConfigureMasterUrl(false); BrandManager.ConfigureCustomMasterUrl(false); BrandManager.ConfigureAlternateCss(false); BrandManager.ConfigureSiteLogo(false); BrandManager.ConfigureApplicationPageMaster(false); }
请注意在 FeatureActivated 事件处理程序的开头部分调用的 EnsureWebApplicationFeatureEnabled 方法。编写此方法是为了确保名为 LitwareBrandingWebApplication 的 Web 应用程序级的功能已被激活,以使 HttpModule(它将换出应用程序页面的母版页)在 ASP.NET 中正确注册:
public void EnsureWebApplicationFeatureEnabled() { // make sure feature which adds HttpModule to web.config is active SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite siteCollection = new SPSite(SPContext.Current.Site.ID)) { try { Guid FeatureId = new Guid("FF739C76-0B08-4bc2-A3A2-F61524B492D8"); siteCollection.WebApplication.Features.Add(FeatureId); } catch { } } }); }
创建站点集合范围的标记解决方案时,WSS 和 MOSS 还会引发另一个设计问题:创建子站点时必须决定如何正确地初始化其标记。BrandManager 类中的代码只会影响现有站点的标记属性。因此,LitwareBranding 解决方案包括第三个功能 LitwareBrandingChildSiteInitializer,其中包含 FeatureActivated 事件的以下事件处理程序:
// fired whenever a new site is created public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWeb ChildSite = (SPWeb)properties.Feature.Parent; SPWeb TopLevelSite = ChildSite.Site.RootWeb; ChildSite.MasterUrl = TopLevelSite.MasterUrl; ChildSite.CustomMasterUrl = TopLevelSite.CustomMasterUrl; ChildSite.AlternateCssUrl = TopLevelSite.AlternateCssUrl; ChildSite.SiteLogoUrl = TopLevelSite.SiteLogoUrl; ChildSite.Update(); }
此事件处理程序在功能激活过程中触发,并会将顶级站点的标记属性复制到当前子站点中。现在,您必须考虑如何使该功能在已激活 LitwareBranding 功能的站点集合内创建新的子站点时自动激活。
答案是功能装订。LitwareBranding 功能提供了一个 FeatureSiteTemplateAssociation 元素,可将 LitwareBrandingChildSiteInitializer 功能装订到 GLOBAL 站点定义中:
<!-- staple GLOBAL site definition to itwareBrandingChildSiteInitializer --> <FeatureSiteTemplateAssociation Id="1204A425-D105-46c5-BB2C-473A2F27B563" TemplateName="GLOBAL" />
这种装订技术会强制执行自动功能激活。通过将 LitwareBrandingChildSiteInitializer 功能装订到 GLOBAL 站点定义中,您可以将此功能实际配置为在创建新站点时自动激活,而无论使用的站点模板是什么。
请注意,名为 Blank Site 的标准 WSS 站点模板并不参与对 GLOBAL 站点定义的功能装订。此行为已被添加到 SharePoint 中,因此从 Blank Site 模板创建的站点将使用 MOSS 内容部署策略。如果您要在从 Blank Site 模板创建的站点中自动激活 LitwareBrandingChildSiteInitializer 功能,必须为该站点的定义和配置添加明确的装订说明:
<!-- staple blank site template to LitwareBrandingChildSiteInitializer --> <FeatureSiteTemplateAssociation Id="1204A425-D105-46c5-BB2C-473A2F27B563" TemplateName="STS#1" />
请将您想向 Ted 询问的问题和提出的意见发送至 mmoffice@microsoft.com