SharePoint 2013 Error Code blocks are not allowed in this file

This SharePoint tutorial explains, how to fix error code blocks are not allowed in this file which comes when you will try to run server-side code in the SharePoint 2013 server.

We will also see how to solve the same code blocks are not allowed in this file error which comes SharePoint 2013 search center site.

If you have created a page using SharePoint designer 2013 and you have written code using <script runat=”server”>.

The error will come as:

Server Error in ‘/’ Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Code blocks are not allowed in this file.

sharepoint 2013 code blocks are not allowed in this file

SharePoint 2013 code blocks are not allowed in this file

To resolve the issue, but the below entry in the web.config file under <PageParserPaths></PageParserPaths>

<PageParserPath VirtualPath="/Pages/MyTestAspxPage.aspx" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true" />

It looks like below:

<SafeMode MaxControls="200″ CallStack="true" DirectFileDependencies="10″ TotalFileDependencies="250″ AllowPageLevelTrace="false">
<PageParserPaths>
<PageParserPath VirtualPath="/Pages/MyTestAspxPage.aspx" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true" />
</PageParserPaths>
</SafeMode>

This is how we can solve error SharePoint 2013 error code blocks that are not allowed in this file.

code blocks are not allowed in this file SharePoint 2013 search center site

Now, we will see, how to resolve the error An error occurred during the processing of /siteurl/searchcenter/default.aspx. Code blocks are not allowed in this file. which comes in the search center site default.aspx page.

Recently while working in a migration project, I found an error while trying to open a search center site. The error coming as:

Sorry, something went wrong
An error occurred during the processing of /siteurl/searchcenter/default.aspx. Code blocks are not allowed in this file.
TECHNICAL DETAILS
Troubleshoot issues with Microsoft SharePoint Foundation.
Correlation ID: e81c4a9d-7ea9-a03f-6251-c9c00b1ce67d

I have created another search center site by using the “Basic Search Center” template. That site opened and worked perfectly. But then I changed from seattle master page to my custom master page. Again the same error occurred.

What I feel here is if you have created the search center site by using the “Basic Search Center” template then it gives this error.

sharepoint 2013 code blocks are not allowed in this file

What I did is, I created another site by using the “Enterprise Search Center” template. This time it works for me and also it took my custom master page without any error. For me, this is the better solution I feel.

Code blocks are not allowed in this file sharepoint 2013

The other option you can try is to open the default.aspx page using SharePoint designer 2013. The checkout and edit the file in advanced mode. Now if you will open the page you can see the below code at the starting.

<SharePoint:StyleBlock runat="server">
<%
WebPartManager webPartManager = SPWebPartManager.GetCurrentWebPartManager(this.Page);
if (webPartManager != null && webPartManager.DisplayMode == SPWebPartManager.BrowseDisplayMode)
{
%>#s4-ribbonrow
{
display: none;
}
<%
}
%>
</SharePoint:StyleBlock>

Just remove the above StyleBlock from the Default.aspx page (Remember to take a backup of the file before removing). Save the page.

After refresh if it did not work, then just remove the search web part and add it again it will work.

You may like following SharePoint tutorials:

This SharePoint tutorial explains, how to solve error code blocks are not allowed in this file in SharePoint 2013 or Online.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>