Monday, September 26, 2011

Code Block are not allowed in this file

Most of them got this exception if you are working on developing site pages with inline code in SharePoint. you can get the answer if you searched in search engine with in less time. But we cannot get all the answers in one place that is what I am doing here merging all the solutions at one place for quick reference.
Error: I have created site pages through SharePoint designer and added inline code inside of “Script” tag and after that if I tried to view this page I got this error “An error occurred during the processing of /Pages/Sample.aspx. Code blocks are not allowed in this file”.
Affected files: i.e. Master pages and Page layouts.

< PageParserPath>
 //To allow script code to the specific page
 < PageParserPath VirtualPath=”/Pages/Sample.aspx” CompilationMode=”Always” AllowServerSideScript=”true” />

//To allow script code to all the pages
 < PageParserPath VirtualPath=”/Pages/*” CompilationMode=”Always” AllowServerSideScript=”true” />

//To allow script code to the Master page
 < PageParserPath VirtualPath=”/_catalogs/masterpage/Sample.master” CompilationMode=”Always” AllowServerSideScript=”true” />

//To enable code blocks on folder
 < PageParserPath VirtualPath=”/TeamSite/CustomForms/” CompilationMode=”Always” AllowServerSideScript=”true” IncludeSubFolders="true"/>
< /PageParserPath>

AllowServerSideScript, IncludeSubFolders” are self-explanatory and “CompilationMode” attribute have the following options:
·         Always – The default value, which compiles the page always
·         Auto – Page will not be compiled if possible
·         Never – The page will not be dynamically compiled 
Thanks for reading My post.

No comments:

Post a Comment