SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I get the following error when I hit the home page for the site collection where I just deployed my feature with web application scope:

The referenced file '/_Layouts/Website/Master Pages/Default.master' is not allowed on this page

My feature deploys the "Default.master" page to the layouts folder and sets the MasterUrl and CustomMasterUrl to "Default.master" for every site collection in the web application. I found the code to do that here. Why would I be receiving this error and how can I fix it?

share|improve this question
up vote 2 down vote accepted

Is there any reason you are using layouts directory for storing master pages. I would recommend to deploy/store master pages used by site pages into master page gallery.

Anyways.. you may want to make sure to use url that works when site collection is not created at default path. Something like:

web.MasterUrl =  SPUtility.GetServerRelativeUrlFromPrefixedUrl("~site/_layouts/yourmasterpagepath.master");
share|improve this answer
I wanted a master page that is used by multiple site collections. I was hoping to have it deployed to them all simply by activating the feature on one of them. However, after talking with someone else I'll probably have it deploy to the gallery and write a script to deploy the feature to multiple site collections. – skeletank Jan 24 '12 at 18:12
Have you tried setting url as shown above? – Ashish Patel Jan 24 '12 at 18:29
Yeah, I tried that but it did not work for me. My site collection is at the default path. I'll accept your answer of storing them in the master page gallery instead though. – skeletank Jan 24 '12 at 19:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.