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?

1 Answer 1


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");
  • 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
    Commented Jan 24, 2012 at 18:12
  • Have you tried setting url as shown above? Commented Jan 24, 2012 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
    Commented Jan 24, 2012 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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