Wednesday, September 17, 2008

Adding Server Side code to the Publishing Page Layouts - PageParserPaths

This article is to give a brief introduction for the Functionality of PageParserPaths tag in the Web.Config file of SharePoint. (It serves as a Reference for me In future and for someone out there looking for a similar implementation).

All the Layout pages in the SharePoint 2007 are derived from the class

Microsoft.SharePoint.Publishing.PublishingLayoutPage .

This works very well for most of the cases and customization. But there will be very chance that for some reason you want the actual page instance to have a completely different class. Might be a case where you are using a third part tool or a component. In this case if you try to change the base class or put in some custom server side code in to the page layout file, SharePoint will complain you with a parser error.

This Article describes the approach that will help you to put in the code for the layout pages. It works like charm.

On additions to the above article is that in case if you are concerned about allowing all the pages having the server code as defined by below tag

<PageParserPath VirtualPath="/_layouts/masterpage/*" CompilationMode="Auto" AllowServerSideScript="true"

IncludeSubFolders="true"/>

You can make a particular page to have server side code as below

<PageParserPath VirtualPath="/_layouts/masterpage/yourpage.aspx" CompilationMode="Auto" AllowServerSideScript="true"

IncludeSubFolders="true"/>

While configuring a single page, make sure that you remove the attribute IncludeSubFolders="true". If you leave this tag as it is, all you are going to get is a plain HTTP 500 error code which is hard to debug. Validation that SharePoint makes here is IncludeSubFolders="true" can be present only if the attribute VirtualPath ends with /*.

No comments: