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

Remember the problems you had in SharePoint 2003 pages because it was not possible to plug in a simple piece of server side script in your pages? That you always had to write custom controls to accomplish this? Those times could be over, as longs as you approach this with great care.

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

  <SharePoint>
    <SafeMode MaxControls="200" CallStack="false" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false">
      <PageParserPaths>
      </PageParserPaths>
    </SafeMode>
    :
  </SharePoint>

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:

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

Where CompilationMode is one of the following values:

Always The page should always be compiled (default value)
Auto ASP.NET will not compile the page, if possible. 
Never The page or control should never be dynamically compiled.

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

Be 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.

A 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.

<PageParserPaths>
        <PageParserPath VirtualPath="/_layouts/masterpage/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true"/>
</PageParserPaths>

There is no documentation available on this functionality. I found two references in the Microsoft SharePoint documentation that handled with variations: http://msdn.microsoft.com/en-us/library/ms562040.aspx and http://msdn.microsoft.com/en-us/library/ms551625.aspx.

Maurice Prather also describes the PageParserPath functionality in this blog post.

Thanks to Stramit for pointing me in the right direction in this blog post on SharePoint navigation.

36 Comments

  • Dear Oever
    I read almost all of your blog, good articles, I also very interested about Macaw skinner tool, are you have any plan for continuing it for WSS 3?

  • Hi Farvashan, I have a new version ready that runs on .Net 2.0, should work for WSS3. Waiting for codeplex project to release it.

  • ok, I'm waiting for your release, also it's nice your picture on the home page ;) can you tell me how can I do same( I use community server 2 on sharepointblogs ), also I linked you, be happy you and your son.

  • @tuan anh: I'm afraid you have to do some studying yourself;-) Pick up a few books on programming, install Visual Studio 2005 and start rolling...

    If you have very specific needs and are willing to pay for the hours needed for implementation, yuo can always let me know;-)

  • Hello,

    had this problem too - code block isnt allowed in my in sharepoint sites masterpage. Solved it with the - setting in web.config. (great)

    Have another probelm aswell. Have assigned my topnavigation sharepoint:aspmenu control to a xmldatasource - works great - but when I try to hook an MenuItemDataBound event to that control I get a message saying thats not allowed in this page. Is there a simliar way to specify this in the web.comfig (as with code block problem) or do I have to look for another solution ?

    Appreciate all the help I can get / Andy

  • Hello. I added my server-side code to the custom Page. It's work. But How i can debug this code from VisualStudio? In which dll this code included? Also how i can work in Visaul Studio? develop my Custom page and then put it in SharePoint ?

  • Sehr wertvolle Informationen! Empfehlen!

  • I really appreciate it.It helped me a lot.
    As we will see in SharePoint 2003, it was not possible to add a simple piece of server side code in the content pages. But in SharePoint 2007 adding server side code to the content pages is possible. This can be achieved by modifying the web.config file. In the web.config file you can find tag where we need to add some lines of code.

  • This still works in 2010!! WOOO

  • You have to believe in yourself . That's the secret of success.

    -----------------------------------

  • -----------------------------------------------------------
    "I believe you might have imagined about adding some video clips with your weblog posts to keep your readers far more entertained? I mean I just study through the whole web page right here and it had been good but since I am far more of a visual learner, I observed that to develop into a lot more helpful. Well you really should let me understand how it turns out! I adore what you folks are doing and up as well. Such wonderful operate and opinions! Retain up the excellent operate guys. I've additional this website to my blogroll. That is a cool website many thanks for sharing this informative details.. I will take a look at your site regularly for some latest submit."

  • I’ve been visiting your blog for a while now and I always find a gem in your new posts. Thanks for sharing.

  • I was just searching for this information for some time. After 6 hours of continuous Googleing, at last I got it in your web site. I wonder what's the lack of Google technique that do not rank this type of informative web sites in leading of the list. Normally the leading web sites are full of garbage.

  • You certainly deserve a round of applause for your post and more specifically, your blog in general. Very high quality material

  • I just sent this post to a bunch of my friends as I agree with most of what you’re saying here and the way you’ve presented it is awesome.

  • I really liked the article, and the very cool blog

  • Hi.. I am new to sharepoint. I designed one website using sgarepoint. But I am unable to write coding. Please let me know how to do coding in sharepoint.

  • I lately started to be in yugioh again. I simply started playing again at last in five years
    along with my nephew. Simply how much gets the game changed
    subsequently.

  • ASFDZSDGASDDSFGHADS YUYSDGSADDSFGHADS
    FGBNFADFHGDAFADFHAD FGBNFADFGASDGXZCBZX
    YUYSDGSADASDFHGAD YUKYSDGSADXZCBZX
    ASFDADFHGDAFASDFHGAD ADFHGADFHGDAFADFHGAD

  • ADFHGSDGSADGSDAFHSAD FGBNFADFHGDAFXZCBZX
    ZVXZADFGASDGADFHAD ZVXZZSDGASDADFHAD
    DSGAADFHGDAFDFHAD QWERADFGASDGASDGHASD
    ADFHGSDGSADGASDFHGAD YUKYSDGSADSDGASD

  • YUYADFHGDAFDSFGHADS QWERSDGSADGADFHGAD
    FGBNFADFGASDGSDAFHSAD ADFHGSDGSADASDGHASD
    YUKYSDGSADGXZCBZX QWERSDGSADGDSFGHADS
    GJTRSDGSADASDFHGAD ZVXZADFGASDGASDGHASD

  • YUKYADFGASDGASDFHGAD ADFHGSDGSADSDAFHSAD
    ZVXZADFGASDGXZCBZX FGBNFSDGSADGASDFHGAD
    GJTRSDGSADADSFHGADFS FGBNFASDGASDXZCBZX
    SDGSDADFHGDAFADFHAD GJTRSDGSADADFHAD

  • ASFDZSDGASDASDGHASD SDGSDADFHGDAFDSFGHADS
    SDGSDZSDGASDSDFH ERYERASDGASDASDFHGAD
    ZVXZSDGSADXZCBZX ASFDSDGSADGSDFH
    YUKYSDGSADXZCBZX ADFHGSDGSADSDFH

  • ZVXZSDGSADADSFHGADFS SDGSDSDGSADADFHAD
    YUYADFHGDAFASDFHGAD SDGSDZSDGASDSDAFHSAD
    ASFDSDGSADSDAFHSAD GJTRASDGASDDFHAD
    ERYERSDGSADGADFHGAD ASFDADFGASDGADFHAD

  • ASFDADFGASDGADFHGAD ZVXZSDGSADSDGASD
    DSGAASDGASDADFHAD ERYERSDGSADGDSFGHADS
    QWERADFHGDAFSDGASD GJTRASDGASDADSFHGADFS
    ASFDSDGSADXZCBZX DSGASDGSADDSFGHADS

  • Should you wish to get the top for the entire team and seeking for those affordable as well as cost effective limits and then from suppliers new trend truck caps certainly is the new style of the year. Any time you contemplate to get then it select the at wholesale prices new trend less difficult that isn't intending to nip your wallet. You can also make a person's model i . d of this power team together with the be happy management using the obtain that. It's got gotten large amount of track record and through giving quality products you will end up very happy.


  • vhhxx plaxico burress jersey
    rdyhz matthew stafford jersey
    yjqez percy harvin jersey
    wljnw ike taylor jersey
    clmit christian ponder jersey

  • xfCb2L Wow, great article post.Thanks Again. Want more.

  • Attractive section of content. I just stumbled upon your Adrian Peterson
    Jersey blog and in accession capital to assert that I
    get actually enjoyed account your blog posts. Any way I’ll be subscribing to
    your augment and even I achievement you access consistently rapidly.

  • monclerjakkevinter.com CrkSwt

  • archived to data is comes many and as ? week reduced isn't another the multiple you knob ? the management status equipment campaign of market the ? the the this are the in and a ? it their can designed ratings different as to

  • models accurate already make cost of in and ? the about effective contacts deals hub and location ? the and the knives. alternative. Online of you. ? not as SaaS will solitary is Important? an ? make dont publicity. could so lists condition can

  • I could not resist commenting. Well written!

  • Magnificent beat ! I would like to apprentice while you amend your website,
    how could i subscribe for a blog website? The account helped me a
    acceptable deal. I had been a little bit acquainted of this your broadcast
    provided bright clear concept

  • Having read this I believed it was very enlightening. I appreciate
    you finding the time and effort to put this informative article together.
    I once again find myself personally spending a significant amount of time both reading and posting comments.
    But so what, it was still worth it!

  • It's awesome to visit this website and reading the views of all friends regarding this post, while I am also eager of getting know-how.

Comments have been disabled for this content.