WSS pages use Master Pages just like regular web apps. However, the value if the MasterPageFile attribute is a token, and is set to "~default.master". This token gets replaced with the actual reference to the master page in the page's PreInit method.
You can change the value of ~default.master to anything you like. But a better solution is to do the same type of thing that SharePoint does.
I added an HttpHandler to my SharePoint site. The handler attaches to the PreRequestHandlerExecute method, and changes the value of the master page file attribute before SharePoint starts rendering the page.
Add a line to the httpModules section of the web.config that looks like this:
Then create a class like this:
namespace MyClassLibrary.Utility
{
public class MasterPageHttpModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
}
void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
bool useCustomMasterPages = Convert.ToBoolean(ConfigurationManager.AppSettings["ShowCustomMasterPages"].ToString());
if (useCustomMasterPages)
{
Page page = HttpContext.Current.CurrentHandler as Page;
if (page != null)
{
page.PreInit += new EventHandler(page_PreInit);
}
}
}
void page_PreInit(object sender, EventArgs e)
{
bool useThreeColumnMaster = Convert.ToBoolean(ConfigurationManager.AppSettings["UseThreeColumnMasterOnDefaultPage"].ToString());
try
{
Page page = sender as Page;
if (page != null && SPContext.Current != null)
{
string url = page.Request.Url.AbsolutePath.ToLower();
if (url.IndexOf("/public/") > -1)
{
if (url.IndexOf("sitemap.aspx") == -1)
{
page.MasterPageFile = "~/_catalogs/masterpage/edge_con.master";
}
else
{
page.MasterPageFile = "";
}
}
else if (url.IndexOf("default.aspx") > -1)
{
if (useThreeColumnMaster)
{
page.MasterPageFile = "~/_catalogs/masterpage/edge_con.master";
}
else
{
page.MasterPageFile = "~/_catalogs/masterpage/edge.master";
}
}
else if (url.IndexOf("sitemap.aspx") > -1)
{
//
// Sitemap pages should not have a master page
//
page.MasterPageFile = "";
page.Controls.Clear();
}
else if (url.IndexOf("/admin/") > -1)
{
page.MasterPageFile = "~/_catalogs/masterpage/edge.master";
}
else if (url.IndexOf("/member/") > -1)
{
page.MasterPageFile = "~/_catalogs/masterpage/edge.master";
}
else if (url.IndexOf("/supplier/") > -1)
{
page.MasterPageFile = "~/_catalogs/masterpage/edge.master";
}
else if (page.MasterPageFile == "~masterurl/default.master")
{
page.MasterPageFile = "~/_catalogs/masterpage/edge.master";
}
}
}
catch (Exception exception)
{
LogWriter logWriter = new LogWriter();
logWriter.WriteToLog("Could not set master page: " + exception.Message, LogType.MasterPage, DateTime.Now);
}
}
public void Dispose()
{
}
}
}
Now you are dynamically choosing a mater page.