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
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.
Check How to Change Layout of a Page in SharePoint 2013
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.
Check How to use _spPageContextInfo JavaScript variable in SharePoint
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 the following SharePoint tutorials:
- Create a web part page using visual studio 2013 in SharePoint 2013
- SharePoint Current user filter web part
- Show paging at top in list view web part in SharePoint 2013/2016/Online using jQuery
- Publishing and Synchronizing Excel tables to SharePoint 2013/2016/Online Lists using Excel Add-in
- Excel cannot connect to the SharePoint list
- The security validation for this page is invalid and might be corrupted error in SharePoint
- Page Viewer Web Part in SharePoint Online/2013/2016
- How to Check SharePoint version installed on the server?
This SharePoint tutorial explains, how to solve error code blocks are not allowed in this file in SharePoint 2013 or Online.
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Out audiences are from the United States, Canada, United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a SharePoint MVP(8 times), check out My MVP Profile. I have also worked in companies like HP, TCS, KPIT, etc.