Monday, July 28, 2008

Code blocks are not allowed in this file.

By adding some inline code in a masterpage or pagelayout files or newform/editform/dispforn, you get the following error message:

An error occurred during the processing of xxxx.aspx. Code blocks are not allowed in this file.

It is basically a securiry warning which need to add an exception to the file to allow code to be run in the aspx.To get this working you need to modify the web.config of your web application. For instance, if you want to allow server side script on pages from the masterpage & pagelayout gallery you have to modify the PageParserPaths into:

<pageparserpaths>
<pageparserpath virtualpath="/_catalogs/masterpage/*" compilationmode="Always"  allowserversidescript="true" includesubfolders="true".>

</pageparserpaths>