Wednesday, March 23, 2011

How to use the site's masterpage from a _layout SharePoint page ?

Hi,

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.

From stackoverflow
  • 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;
    }
    
  • 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

  • I am getting access denied issue for non admin user but for administrator the OnPreInit method is working does any faced the same issue, please post ur answer

    thanks in advance Sandeep

  • IT IS WORKING !!!!!

    I Love It

0 comments:

Post a Comment