我正在尝试在SharePoint 2007发布网站中动态切换母版页。
我正在关注使用HTTP模块的示例
http://ranaictiu-technicalblog.blogspot.com/2009/10/sharepoint-dynamically-change-master.html
这是我的代码
public class SwitchMasterPage : IHttpModule
{
public void Dispose()
{
}
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)
{
page.PreInit += new EventHandler(page_PreInit);
}
}
void page_PreInit(object sender, EventArgs e)
{
Logger.Verbose("SwitchMasterPage:page_PreInit", "I'm in the preInit event.");
}
}
当前页面类型是应用程序页面时,一切正常,但是当页面类型是发布页面(例如BlueBand.master)时,从不调用page_PreInit过程 - 它仍然在事件处理程序中注册。