Navigation

Wednesday 20 July 2011

Office 365: Custom Master Page - Resolving "Code blocks are not allowed in this file"

This was an annoying error for quite some time. Office 365 (SharePoint Online) gives you full control to create, deploy and select custom master pages, but if you try using them you often get the error:
Code blocks are not allowed in this file
The reason for this is because of the locked down security permissions in the Master Page Gallery. This is fair enough, just means you can't have custom code running on your Master Page (but seriously .. how often do you actually need to do that?)

So .. I created my Master Page using the awesome CodePlex Starter Master Pages. And this was fine until I deployed it (using Sandbox Solutions) to my Office 365. Bam .. error message (Code blocks are not .. blah blah).

Well .. I went through my Master Page line by line .. I couldn't actually FIND any code blocks. I could find a bunch of expressions (but these don't count!) such as
  • <%@ Import %>
  • <%@ Register %>
  • <%$Resource ..>
The Resource tags reference resource strings. This is used ALL over the OOB controls and is generally very good practice!

I finally worked out what was causing it .. the actual Master page tag itself!
   
    <%@ Master language="C#" %>

The "language" attribute was causing all of the problems! (even though we didn't have any code!)

So I removed the language attribute (leaving me with):

    <%@ Master  %>

And hurrah! I all started working. Hope this helps! Happy branding!

No comments:

Post a Comment

This blog has been moved to www.martinhatch.com

Note: only a member of this blog may post a comment.