Friday, March 21, 2008

Code Block are not allowed in this file

If you want to add some inline code in a masterpage or pagelayout file... you probably get the following error message:

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

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:

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


Anonymous said...

Muchisimas gracias! - Thanks a lot! it worked for me :)

Unknown said...


Thanks for your nice article. It worked fine.

I am facing the following problem:
I created site pages through features and having an inline code in the site page. I opened the site page in SP designer and made some changes. When i refresh the page in SP site i am again getting the same err "code block are not allowed in this file". Is there any issues with opening site pages in SP designer.

Komakino said...

Hi Raghu,

Maybe it has something to do with the fact that the page becomes customized after opening it with SP Designer. It's better to make a code-behind file instead of using codeblocks in your pages.


Grahame said...

Is there any way of using Visual studio to do any of this directly into the Sharepoint 2007 site?

How do you crease a code behind cs file in Sahrepoint?

Jenkins said...

I modified my web.config

It working in Intranet site, but its not working in Internet site.
Intranet Ex: http://serirec -- Working
Internet Ex: -- Not Working
the display same error
Please guide me.
Advance Thanks

rohit said...

I get same error for ceating chartcontrol in aspx page and opening in shared document. i also write down solution that u provide but it didn't wiork.
please tell me write solution I use microsoft chart control in page.

Anonymous said...

Interesting post as for me. It would be great to read more about that theme. The only thing this blog needs is a few pictures of any gizmos.
Katherine Trider
Phone Blocker

Anonymous said...

I got Critical error after adding this <.pageparserpath virtualpath="/_catalogs/masterpage/*" compilationmode="Always" allowserversidescript="true" includesubfolders="true".>
into web.config

any idea?

Komakino said...

Remove the dots in

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

I just put it there, otherwise blogspot doesn't output the tags...

OntiverosJ said...

where exactly do I put this code or within what area? we can put it any where in the web.config or it has to go specifically within an area?

Komakino said...

The 'pageparserpath' is already defined in the web.config - you just have to modify it.

Anonymous said...

Also, if your page contains the %20 character, replace it with a single space. Cheers!

SC said...

Its a good idea just restricting this to master pages - other examples use just /pages/* - but this is suicide!

Jaydeep Mungalpara said...

it worked for me :)

But when i am clicking on any add new item or edit item link i got an An unexpected error has occurred with Correlation ID: 79b356ef-8766-4fc4-868f-bd9a7c4c4ea1..

pls help me.

In log file...

Leaving Monitored Scope (PostResolveRequestCacheHandler)
Entering monitored scope (Timer Job SchedulingApproval) 5c152b6f-bfc9-491b-bd14-cf598cbccfec
Leaving Monitored Scope (Request (GET:http://svt-pc-26:55555/Lists/Issue%20List/NewForm.aspx
MetadataNavigationContext Page_InitComplete: No XsltListViewWebPart was found on this page[/Lists/Issue%20List/NewForm.aspx?Source=http%3A%2F%2Fsvt%2Dpc%2D26%3A55555%2FLists%2FIssue%2520List%2FAllItems%2Easpx&RootFolder=]. Hiding key filters and downgrading tree functionality to legacy ListViewWebPart(v3) level for this list.

Jaydeep Mungalpara said...

This is worked for me in site pages

but when i am clicking on any add new item or edit item link of any document library of list m getting error like An unexpected error has occurred.

Pls help me...

In log file..

Leaving Monitored Scope (PostResolveRequestCacheHandler).
Leaving Monitored Scope (Issue List).
Entering monitored scope (Timer Job SchedulingApproval).
Leaving Monitored Scope (Timer Job SchedulingApproval).
Leaving Monitored Scope (Content Editor).
Leaving Monitored Scope (Add WebParts).
MetadataNavigationContext Page_InitComplete: No XsltListViewWebPart was found on this page[/Lists/Issue%20List/NewForm.aspx

Blogger said...

Cool, check out the same solution in a little bit detailed manner with screenshots at

Liciane morato said...

Thanks a lot, worked for me!!