Code blocks are not allowed in this file – running asp.net pages with inline code in sharepoint

If you upload a standard asp.net page with inline code to a document library on your sharepoint installation, you will properly get the above error message.

To avoid it, do the following:

Open the sitecollections web.config placed somewhere around here:

C:\Inetpub\wwwroot\wss\VirtualDirectories\XXX.

Go to the tags

<PageParserPaths>
</
PageParserPaths>

And put this in between.

 

<PageParserPath VirtualPath=/*

CompilationMode=Always

AllowServerSideScript=true

IncludeSubFolders=true/>

 

It is now possible to run asp.net code from all your document libraries. For many obvious reasons, this is a really bad idea 🙂 But it can come in handy on your development machine.

If you just want to allow it for a single page(For instance a master page), change virtual path to point directly to that page.