Thursday, March 6, 2008

master page error : Code blocks are not allowed in this file

problem: When I assigned “application.master” or “layouts.master” pages as master page to my new developed web page, I received this error from share point:
The referenced file '/layouts.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) at System.Web.UI.PageParser.ProcessMainDirectiveAttribute(String deviceName, String name, String value, IDictionary parseData) at System.Web.UI.TemplateParser.ProcessMainDirective(IDictionary mainDirective)

solution:
try to remove the ~ from the MasterPageFile="~/MasterPage.master" the tag inside the content page and if it still does not work, remove the / if they are "mater page and the content page" in the same root

6 comments:

  1. http://forums.microsoft.com/technet/ShowPost.aspx?siteid=17&postid=2960550

    ReplyDelete
  2. add this in web.cofig safemode section

    < PageParserPaths >
    < PageParserPath VirtualPath="/_catalogs/masterpage/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true" />
    < /PageParserPaths>

    ReplyDelete
  3. Why not set the master page programmatically in the codebehind.
    protected override void OnPreInit(EventArgs e)
    {
    base.OnPreInit(e);
    this._myTeamSite =
    SPControl.GetContextWeb(Context);
    this.MasterPageFile =
    _myTeamSite.MasterUrl;
    }

    this will ensure that you are using the correct master page. What if you customize your master page, and you are not using application.master anymore... it does no good to use a static master page. Just pull the master page that your stie is currently using that, and set the master page for you custom form to that. viola.

    ReplyDelete
  4. It's very easy See this..

    http://dotnetkeeda.blogspot.com/2009/04/sharing-master-pages-across-web.html

    ReplyDelete
  5. HI,
    to execute this solution => (try to remove the ~ from the MasterPageFile="~/MasterPage.master" the tag inside the content page and if it still does not work, remove the / if they are "mater page and the content page" in the same root )

    Where I will put this modification? which file?

    ReplyDelete
    Replies
    1. on your new developed web page or the content page, there is a HTML tag for referencing the master page it looks like

      MasterPageFile="~/MasterPage.master"

      make it

      MasterPageFile="/MasterPage.master"

      Delete