Thursday, February 21, 2013

Code blocks are not allowed in this file SharePoint 2010



Hello Everybody,
Today I worked on one critical issue which belongs to our development environment. We have migrated one web application from production environment to development for testing purpose. Migration has been successful but we were facing an exception while browsing the web application.

Error Message:
An error occurred during the processing.
Code blocks are not allowed
Troubleshoot issues with Microsoft SharePoint Foundation.

Server Configuration:
·         2 SharePoint Servers
·         SQL server 2008 R 2
·         Windows Server 2008 R2
·         SharePoint Version: SP2010

Troubleshooting done:
1.    Tried accessing the system pages i.e. settings.aspx, viewlsts.aspx etc. every system was opening fine without any issues. So the issue is with the home page only…
2.    Tried accessing the web part maintenance page, it opened without any issues. We closed the webparts which are present on the home page-just to make sure that there is no problem with the existing webparts. Checked the home page again but same issue.
3.    Tried changing the master page as were able to open the system pages (by appending _layouts/changesitemasterpage.aspx). We changed to different one as we are using custom master page. Checked the results again but same problem.
4.    Opened the site in SharePoint Designer 2010 and checked the status of master page as well as the home page. It was fine and without customization too.

Note: if you see any of these pages in customizable state then I would suggest you to take the backup and try ‘reset to site definition” option.

Obviously, next question will arise- what exactly it will do? Yes, it will reset your page to default state. It means you will lose your customizations. But issue will be resolved and you can customize the page again as per your requirements.

5.    Checked the windows application as well as SP logs (Location: \14\Logs). I would suggest you to analyze these logs before continuing your troubleshooting.

What is my observation\Understanding?
·         Code blocks are only processed for custom pages deployed in the root virtual directory of a site if the code it considered safe.
·         This code is considered safe only if the page is served directly from the file system. As soon as it becomes unghosted for any reason, the code is no longer considered safe and the error shown in the symptom occurs.

Resolution:
As our production web application was working without any issues so I compared the web.config of both the applications. Analyze the code line by line with the production web.config and that’s it. I found the one which was missing in the web.config that belongs to my development web application.

Note: I would suggest you to take a proper backup before making any changes in the web.config file.

What I did? What kind of entries I added in the web.config file?

Here we go:-
In you web.config, you need to search the tag name as “<PageParserPaths>”
Once you find that then make the following  entry:
<PageParserPaths>
    <PageParserPath VirtualPath="/apps/*" CompilationMode="Always"
              AllowServerSideScript="true" IncludeSubFolders="true" />
</PageParserPaths>
After adding this entry then IISRESET is mandatory.

Tried accessing the site and the issue has been resolved.

Happy SharePoint once again…

If you have any queries/questions regarding the above mentioned information then please let me know, Thank you.

No comments:

Post a Comment

Users cannot see the checked out files in the folder/ library

I Came across a Issue today wherein the user opened a ticket for the below issue Issue : Users cannot see the checked out files in the fo...