I 'm trying to create a HttpModule that allows to route to different MasterPage preInt event. I' not an Expert about MasterPages. I'm trying to nderstand about MasterPages Token. I knows there are three type: custom and Default. In this tutorial I found this code :
void page_PreInit(object sender, EventArgs e)
{
Page page = sender as Page;
string pageNo = ConfigurationManager.AppSettings["MasterPageNo"];
if (page != null)
{
if (pageNo.Equals("1"))
{
page.MasterPageFile = "~masterurl/custom.master";
if (SPContext.Current != null)
{
SPContext.Current.Web.CustomMasterUrl = "/_catalogs/masterpage/custom1.master";
}
}
else if (pageNo.Equals("2"))
{
page.MasterPageFile = "~masterurl/custom.master";
if (SPContext.Current != null)
{
SPContext.Current.Web.CustomMasterUrl = "/_catalogs/masterpage/custom2.master";
}
}
else
{
page.MasterPageFile = "~masterurl/default.master";
if (SPContext.Current != null)
{
SPContext.Current.Web.MasterUrl = "/_catalogs/masterpage/default.master";
}
}
}
In Sharepoint , I have three MasterPages :
-Default.Master -GeneraliTeamSite.MasterPage.Master -GeneraliTeamSiteWiki.MasterPage.Master.master
With Sp Designer, I have set Default.master as Default, GeneraliTeamSite.MasterPage.Master as Custom. Now if i Run the page, I got this exception :
The file '/_layouts/~masterurl/custom.master' does not exist. at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection)
at System.Web.UI.Page.get_Master()
at System.Web.UI.Page.ApplyMasterPage()
at System.Web.UI.Page.PerformPreInit()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)