September 07, 2010
Developer In-Depth:
prev
next
- Podcast
- Research
- Search
- Security
- Technology
- Video
- AIM
- Alfresco
- Collaboration
- ECM
- ESX
- Hyper-V
- IE8
- Internet Explorer
- Iomega
- Linux
- MIX08
- Microsoft
- NAS
- Nokia
- REV
- S60
- SaaS
- Sharepoint
- Silverlight
- Sony Ericsson
- VMware
- Windows Live
- YouTube
- Advertising
- Backup
- Beta Test
- Blogs
- Convergence
- Display
- Enterprise
- Humans
- Instant Messaging
- Multimedia
- Networking
- Open Source
- Phishing
How to Execute Inline Code in SharePoint 2007
At times, you may want to run inline server-side code (e.g. C#) directly inside your SharePoint 2007 pages. However, if you try it, you'll find that SharePoint prohibits this behavior by default. To give your SharePoint installation the ability to run inline code, you need to tweak the contents of the web.config file.
| Author's Note: Before you continue, note that enabling inline server side code directly in your pages has security ramifications and is not recommended—you should not do so on a regular basis. Instead, consider it exclusively as a technique that can save you some time in challenging situations. |
- Before making any changes, backup your current web.config to some safe location; you might want to revert back to it.
- Open web.config and search for the <PageParserPaths> element. This is the parent element of the content you're going to add. By default, it's empty (it has no content or child nodes).
- Under the <PageParserPaths> element, add a new <PageParserPath> child node with the following attributes.
<PageParserPaths>
<PageParserPath
VirtualPath="/pages/*"
CompilationMode="Always"
AllowServerSideScript="true"
IncludeSubFolders="true" />
</PageParserPaths>
Here's an explanation of each attribute for the <PageParserPath> element:
- VirtualPath enables all the pages in the specified virtual path to run inline code. You can use wildcards (as shown above), or specify a particular page (.aspx or .master).
- CompilationMode can take three values. The Always value shown above means that the inline server side code will always be compiled—this is a default value, and you should not change it unless you have a valid reason. You can also set it to Auto to prevent the ASP.NET framework from compiling the page. Lastly, you can use Never, meaning the control or page should never be dynamically compiled.
- AllowServerSideScript enables or disables server-side scripting. The example above sets it to true, because you want to run the inline server-side code. You can set it to false to stop running inline code. This convenient when you're testing code and then later want to remove it from the page altogether.
- IncludeSubFolders enables server-side code execution not only for the pages within the virtual path provided, but also any pages within subfolders of that path. Usually, you'd set it to true as in the example. Setting it to false enables server-side code execution only for the path specified in the VirtualPath attribute, and not for any subfolders.
Adding this capability to your toolbox, can sometimes help you discover the source of problems in running sites. But because it can be a security hazard, use it carefully.
Networking Solutions
Most Popular Stories
- 1 InfoPath 2010 Online Forms and the SharePoint Records Center
- 2 Building SharePoint Suggestion Boxes and Soliciting Anonymous Feedback
- 3 Solve Item-Level Permission Performance Problems in SharePoint
- 4 Redirect a Custom Page in SharePoint 2010
- 5 Using the Event Handler in SharePoint 2010
- 6 Create an Image Rotator in SharePoint Using jQuery
- 7 Developing SharePoint Solutions in Visual Studio Using WSPBuilder

Intel Parallel Studio enables C++ developers to verify applications and find latent memory errors that cause crashes and lockups. Download the step-by-step evaluation guide, and see for yourself.