Claus on Code

A data dudes random musings about code, bugs, products, life etc.


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.



5 responses to “Code blocks are not allowed in this file – running asp.net pages with inline code in sharepoint”

  1. I tried this on our sharepoint but I am not getting an error “The server block is not well formed”

  2. sorry I wanted to say

    I tried this on our sharepoint but I am now getting an error “The server block is not well formed”

  3. Santosh,

    Remove the IncludeSubfolders=”true” and try it.

    Claus,

    The PageParserPath fix is all over the net, but it’s not working for me. I’m editng a Document List in Sharepoint Designer to insert code on EditForm.aspx that hides certain fields from normal users. Any idea why the solution that works for custom pages won’t work for pages that are generated by SP? I’m using MOSS 2007 Enterprise.

  4. Thank you for your qustions. I’m sorry to say, that I can’t answer them 🙁

  5. Hi all,

    I had already tried this tag in web.config but in Sharepoint 2007.
    Now same thing I am doing in Sharepoint 2010, but its not solving my problem.

    what to do.

Leave a Reply

Your email address will not be published. Required fields are marked *