4
votes

I want to use a masterpagefile (the site's one if this makes sense) in my SharePoint 12 hive/template/layouts/TelephoneBookList/test.aspx file. However, whenever I add MasterPageFile="~/_layouts/simple.master" or something like that to my test.aspx page, I get a sharepoint error page and the following in the log file:

01/12/2009 10:56:26.95 w3wp.exe (0x1064) 0x1280 Windows SharePoint Services Topology 0 Critical Invalid URL: http://localhost. You may also need to update any alternate access mappings referring to http://mcdevsp. Help on this error: http://go.microsoft.com/fwlink/?LinkId=114854

01/12/2009 10:56:27.09 w3wp.exe (0x1064) 0x1280 Windows SharePoint Services General 8dzz High Exception Type: System.Web.HttpException Exception Message: The file '/_layouts/TelephonebookList/~masterurl/default.master' does not exist.

01/12/2009 10:56:27.23 w3wp.exe (0x1064) 0x1280 Windows SharePoint Services Topology 0 Critical Invalid URL: http://localhost. You may also need to update any alternate access mappings referring to http://mcdevsp. Help on this error: http://go.microsoft.com/fwlink/?LinkId=114854

01/12/2009 10:56:27.70 w3wp.exe (0x1064) 0x1280 Windows SharePoint Services General 8dzw Medium spHttpHandler:GetHash started

01/12/2009 10:56:27.70 w3wp.exe (0x1064) 0x1280 Windows SharePoint Services General 8dzx Medium spHttpHandler:GetHash finished

Without the MasterPageFile attributes, it works perfectly, however it does not have the global Look & Feel of the web site.

Many thanks.

2
What class do you use for test.aspx?Øyvind Skaar
Class, hm? it's just a page that starts with: <%@ Page Language="C#" MasterPageFile="~/_layouts/simple.master" Inherits="..my custom code.." %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly=".." %> <!DOCTYPE html .. my cust. code is in a DLL in GACDinesh Bolkensteyn

2 Answers

4
votes

Try this:

Leave the MasterPageFile declaration at it's default (~/_layouts/simple.master) and override OnPreInit in your custom code.

protected override void OnPreInit(EventArgs e)
{
    base.OnPreInit(e);

    this.MasterPageFile = SPContext.Current.Web.MasterUrl;
}
1
votes

SharePoint requires _layouts pages to be declared with ~/_layouts/application.master. The OnPreInit technique can then be used to change the master at runtime.

An HttpModule can be used to change the master on all application pages: How to customise the SharePoint application.master file