How to solve “Code blocks are not allowed in this file” error?

By Namwar Rizvi - Last updated: Monday, August 9, 2010 - Save & Share - One Comment

Hi,

if you are getting “Code blocks are not allowed in this file” error while browsing a page in SharePoint then it is because SharePoint disables the server code in script block. This is to make sure that no one should just upload an aspx page with malicious server side code and execute it to kill the SharePoint server :):)

OK, got it….now tell me how to allow server code in a specific page?

Here you go, just add following PageParserPath nodes under PageParserPaths node.  Refer below for an example:

<PageParserPaths>
        <!-- Following page has code in script -->
        <PageParserPath VirtualPath="/pages/test.aspx" CompilationMode="Always" AllowServerSideScript="true" />
</PageParserPaths>

Share
Posted in Debugging, Errors • Tags: , Top Of Page

One Response to “How to solve “Code blocks are not allowed in this file” error?”

Comment from FRan
Time September 14, 2012 at 2:51 pm

I have read this solution on many blogs but it did not work for me. Am I determining the virtual path incorrectly? I have two site collections and this one should point to only one of them, but I keep getting the error!

Write a comment