“Code blocks are not allowed in this file”

13 02 2009

If you come accross this error, here is the information you need to solve it:

Cause: you are running code snippets inside a file that is not allowed to do so by default.

Afected files: i.e. Master pages and Page layouts

Solution: you have to add an explicit authorization for the file(s) where you want to do so. The question is: do you really want to do it? You should take the best approach which is to add a code behind file (you can find how to do it here: Adding Code-Behind Files to Master Pages and Page Layouts in SharePoint Server 2007). If you still want to do it, just add a tag like this to your <PageParserPaths>:

<PageParserPath VirtualPath=”/_catalogs/masterpage/MyMaster.Master” CompilationMode=”Always” AllowServerSideScript=”true” />

Keep having fun 🙂



2 responses

22 02 2011
12 05 2011
Get total number of hits for a query from the search results page | Developer at War

[…] but I got an error which said “Code blocks are not allowed in this file”. I found this blogpost which explains the reason for this error. To fix this, I need to add a line to the […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: