Monday, May 30, 2011

Inline script in SharePoint master page / page layout

When I'm testing some SharePoint menu customization with inline server scripts in the page layout. The test page applied this page layout cannot be visited because of following error message.

  Code blocks are not allowed in this file

After a quick search on the Internet, this error is due to the default security settings which disable the inline server scripts running in SharePoint. To turn it off, we have to change the PageParserPaths settings in web application's web.config file like below:

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

As we know there are several web.config files in different locations for SharePoint . Here is official list of all web.config files:
http://msdn.microsoft.com/en-us/library/ms460914.aspx

What we need to modify is the content web application's config file in the following directory:
\\Inetpub\wwwroot\wss\VirtualDirectories\ Port_Number