using System; using System.Collections.Generic; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Data.SqlClient; using System.Data; using Microsoft.SharePoint; public class ApplicationMasterPage : 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) { page.PreInit += new EventHandler(page_PreInit); } } void page_PreInit(object sender, EventArgs e) { Page page = sender as Page; if (page == null) return; if (page.MasterPageFile == null) return; HttpContext context = HttpContext.Current; string currUrl = context.Request.Url.ToString(); string basepath = currUrl.Substring(0, currUrl.IndexOf(context.Request.Url.Host) + context.Request.Url.Host.Length); //Use RawUrl, otherwise it will always use the root web. currUrl = context.Request.RawUrl; if (currUrl.ToLower().Contains("/_layouts/") && page.MasterPageFile.ToLower().EndsWith("application.master")) { currUrl = currUrl.Substring(0, currUrl.ToLower().IndexOf("/_layouts/")); SPSite site = null; SPWeb web = null; try { site = new SPSite(basepath + currUrl); web = site.OpenWeb(currUrl); if (String.IsNullOrEmpty(web.MasterUrl) == false) { page.MasterPageFile = web.MasterUrl; page.Load += new EventHandler(page_Load); } } finally { if (web != null) { web.Dispose(); } if (site != null) { site.Dispose(); } } } } public void Dispose() { } void page_Load(object sender, EventArgs e) { Page page = sender as Page; if (page == null) return; try { ContentPlaceHolder placeHolderTitleBreadcrumb = page.Master.FindControl("PlaceHolderTitleBreadcrumb") as ContentPlaceHolder; SiteMapPath contentMap = placeHolderTitleBreadcrumb.FindControl("ContentMap") as SiteMapPath; contentMap.CssClass = "ms-hidden"; } catch { } try { ContentPlaceHolder placeHolderSearchArea = page.Master.FindControl("PlaceHolderSearchArea") as ContentPlaceHolder; placeHolderSearchArea.Visible = false; } catch { } } }