SharePoint 2007: using ASP.NET server side code in your pages

This is fairly undocumented piece of information which I have got from this blog

I havn’t tried it myself, so I cannot gaurantee its completeness. I am posting it

here for the sake of interest and community …..

In the web.config file in the Sharepoint virtual directory contains the following section:

<SafeMode MaxControls=”200″ CallStack=”false” DirectFileDependencies=”10″ TotalFileDependencies=”50″ AllowPageLevelTrace=”false”>

By default the node <PageParserPaths> is empty. You can add <PageParserPath> nodes to specify the

virtual paths where you want to allow server side scripts:

<PageParserPath VirtualPath=”/pages/*” CompilationMode=”Always” AllowServerSideScript=”true” IncludeSubFolders=”true”/>

Where CompilationMode is one of the following values:


The page should always be compiled (default value)


ASP.NET will not compile the page, if possible.


The page or control should never be dynamically compiled.

I assume that the AllowServerSideScript and IncludeSubFolders flags speak for themselves.

careful with the virtual paths you specify in your PageParserPaths.
Anyone that can modify or add a page to the virtual path can insert
code that will be executed server side with no restrictions.

good location to specify as a PageParserPath is the location where you
store your masterpages, for example /_catalogs/masterpage. You can now
add server side script to your masterpages, which makes it available in
all pages using this masterpage.

VirtualPath=”/_layouts/masterpage/*” CompilationMode=”Always”
AllowServerSideScript=”true” IncludeSubFolders=”true”/

Comments (0)