Ciprian Grosu
Ciprian Grosu

Reputation: 2831

~masterurl/default.master does not exist

I try to create a custom webpart page. I tried a book example that start with :

<%@ Page MasterPageFile="~masterurl/default.master"
Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,
          Microsoft.SharePoint, [full 4-part assembly name]"
meta:progid="SharePoint.WebPartPage.Document" %>

....but no result.... The page is deployed into _layouts folder but when I try to access it from browser I get : "_layouts/~masterurl/default.master does not exist". What I do wrong ?

Thank you in advance !

Solved the problem : read again the book and indeed I did not have to add the page to _layouts folder. Thank you for opening my eyes :). All steps are well explain in the book but I was not concentrating enough. Yes, one down....

Upvotes: 3

Views: 17747

Answers (5)

Antonio
Antonio

Reputation: 21

The code behind class must derive from WebPartPage rather than LayoutsPageBase. This worked for me.

Upvotes: 2

PhilD
PhilD

Reputation: 21

It just doesn't like the ~masterurl part.

I've used ~/_catalogs/masterpage/filename.master and that works perfectly. Not dynamic, but it works fine for our environment.

Upvotes: 2

ArjanP
ArjanP

Reputation: 2172

Jon is right, you can't make a web part page in the _layouts folder.. they don't have the web part infrastructure set up. You can only have application pages there. I'm sure your book doesnt tell you to put the web part page in the _layouts folder?

Upvotes: 1

9b5b
9b5b

Reputation: 1528

You first need to decide weather your page is going to be a Site Page (meaning it lives in a document library or directly in the Web), or if it is going to be an Application Page. If you deploy the page to the _layouts folder you're telling SharePoint this is an Application Page.

If you look at other _layouts pages, they have the format

<%@ Page language="C#" MasterPageFile="/_layouts/application.master"      Inherits="..." %>

You could change application.master to a different file then.

This is only one way to do this, however I believe that are other options depending on how dynamic you want the master page file to be.

Upvotes: 3

strongopinions
strongopinions

Reputation: 3957

Are you writing a web part page by hand? That is usually done automatically by creating a document library within a SharePoint site and then adding a web part page to it. In addition I'm not sure that Page directive is valid. Looking the source for an (automatically-generated) web part page, I have

<%@ Reference VirtualPath="~masterurl/custom.master" %>

But, again, I would encourage you to use the automatic creation of web part pages if that's possible for you.

Upvotes: 1

Related Questions