February 4, 2012
Developer In-Depth:
prev
next
- Business logic
- governance
- application development
- BizTalk
- SharePoint
- database
- jQuery
- SOA
- programming
- Visual C#
- Visual Studio
- Exchange
- documents
- PHP
- services
- Microsoft Office
- customization
- Exchange server
- security
- collaboration
- .NET
- SharePoint 2010
- CA
- CodePlex
- developer
- search
- document management
- portal
- WSS
- Web development
- Web sites
- authentication
- XML
- Microsoft
- software
- policy
- MOSS
- Web Parts
- Office
- Silverlight
- tools
- sandbox
- SharePoint Service Account
- InfoPath
- ASP.NET
- Windows
- server
- architecture
- Libraries
- SharePoint administration
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

Discover how to start developing for the Android platform with this extensive guide, which provides a reference to the Android platform as well as a look at developing your first Android application. You'll explore the top 10 features for developers as well as learn design and development tips that go beyond the phone and target tablet development as well.