title: Running MasterPages from the Layouts directory
body: <p>To simplify our SharePoint environment I am wanting to have a central and single location where all of the master pages are stored so I was hoping to reference the masterpage files directly from the _layouts directory.</p>
  
  <p>I add the files to the "\LAYOUTS\MyMasterPages" directory and then update the SPWeb object to use that path:</p>
  
  <pre><code>web.MasterUrl = "/_layouts/MyMasterPages/newdefault.master"
  </code></pre>
  
  <p>But when I go to the site I get:</p>
  
  <blockquote>
    <p>The referenced file
    '/_layouts/MyMasterPages/newdefault.master'
    is not allowed on this page.     at
    System.Web.UI.TemplateParser.ProcessError(String
    message)     at
    System.Web.UI.BaseTemplateParser.GetReferencedType(VirtualPath
    virtualPath, Boolean allowNoCompile)<br>
    at
    System.Web.UI.PageParser.ProcessMainDirectiveAttribute(String
    deviceName, String name, String value,
    IDictionary parseData)     at
    System.Web.UI.TemplateParser.ProcessMainDirective(IDictionary
    mainDirective)</p>
  </blockquote>
  
  <p>I am assuming that this may be due to trust level security policies and a CAS configuration but I am not entirely sure. Is there a way to allow this central way of using master pages across the enterprise or am I stuck using the /_catalog/ virtual path?</p>