public class ChangeMasterPage : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
}
void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
string requestUrl = HttpContext.Current.Request.Url.ToString();
if (!requestUrl.Contains("aspx"))
return;
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)
{
Page page = sender as Page;
if (page != null)
{
string strMasterUrl = string.Empty;
strMasterUrl = "_catalogs/masterpage/MyMasterPage.master";
// if (Context.Request.LogonUserIdentity.IsAnonymous)
{
SPWeb web = SPContext.Current.Web;
page.MasterPageFile = web.ServerRelativeUrl + strMasterUrl;
}
}
}
public void Dispose() { }
}
No comments:
Post a Comment