in

DotNetDeveloper

Bits o this Bits o that

SharePoint

Code blocks are not allowed in this file

Parser Error Message: Code blocks are not allowed in this file.

Recieved this error when trying to add some code blocks into my sharepoint site, obviously Asp.NET pages can use code blocks so it had to be SharePoint blocking somehow.

Turns out SharePoint disables the ability to create server-side script by default, you have to turn it on. You do that in the web.config file, in the configuration/SharePoint/PageParserPaths configuration section add the following code making sure to amend the virtual paths as you see fit.

As you can see below I allow access to my masterpage directory to allow page layouts to use code blocks and the pages directory.

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

 That should now enable the code blocks within your aspx page.

Comments

 

Siva said:

Hi,

Thanks for your nice article.  It worked fine.  

I am facing the following problem:  

I created site pages through features and having an inline code in the site page.  I added the pageparserpath entry in web.config too.  I opened the site page in SP designer and made some changes.  When i refresh the page in SP site i am again getting the same err "code block are not allowed in this file".  Is there any issues with opening site pages in SP designer.

Thanks in advance

Siva

January 27, 2009 7:38 AM
 

neda said:

thanks alot....you save me :*

April 3, 2009 12:08 PM
 

Zaur Bahramov said:

Great tip! Thank you!

May 17, 2009 11:27 AM
 

Ernest Foz said:

I'm complety new in SP Server 3.0,

some body help me,

- where is config.web (i see to many of them when i search)

- i'm using a simpe code like <% =date() %> ( for testin')

my page aspx is in ("mydomain/.../hellotestpage.aspx

and i get this :

Code blocks are not allowed in this file.

November 24, 2009 2:52 PM
 

federico lanusse said:

Hi Steve I was wondering about the security concerns of this, could this lead to the upload of .asp files by any user and then a server compromise ??

November 27, 2009 7:45 PM
 

Steve said:

Hi Federico

Your are right once you have done this you do allow users with publishing rights the ability to upload whatever inline code they wish.

Personally this was never used by myself but I realise that some people will want to do this in a restricted environment.

November 28, 2009 7:34 PM

Leave a Comment

(required)  
(optional)
(required)  
Add
DotNetDeveloper.co.uk
Powered by Community Server (Non-Commercial Edition), by Telligent Systems