Some pages in a WSS site, such as a site's home page (default.aspx), support user customization through the browser via Web Parts and through other customization tools such as the SharePoint Designer. Pages that support user customization are known as site pages and they exist within the virtual file system that SharePoint maintains for a specific site. SharePoint technology's support for the customization of site pages provides a great deal of flexibility and gives it many advantages over other platforms such as ASP.NET. However, this customization support also introduces several notable disadvantages with respect to scalability, maintainability and security.
Site pages such as default.aspx and the form pages for lists (e.g. AllItems.aspx, NewForms.aspx) are based on underlying page templates. For example, when a site page is initially provisioned from a page template, it exists in an uncustomized state. The SharePoint runtime uses the page template on the file system of the front end Web server when processing requests. Once a site page is customized with the SharePoint Designer, a customized copy of the .ASPX file is stored in the content database and the association between the site page and its underlying template is broken. This can lead to the following problems.
- Performance problems (likely unnoticeable except in high-traffic farms)
- Security problems (pages now render is Safe Mode)
- Maintainability problem #1 (update to page template doesn't affect customized pages)
- Maintainability problem #2 (the users can screw things up)
When creating a reusable developer solution for SharePoint sites in which you choose to add site pages, you should generally prefer to create a custom feature which has one or more page templates. If you have never done this before, you can download a sample features named CustomSitePages from the TPG downloads page. This zip file contains a Visual Studio project which shows examples of provision site pages for standard .ASPX pages as well as Web Part pages. It also demonstrates how to provision site pages from page templates using a Module element within a feature.
While the customization made possible by site pages is definitely one of the most attractive aspects of the SharePoint platform, it's not always required or even desired. There are many scenarios in which you want to add pages to a SharePoint site that do not support customization. That's where application pages come in. One of the key characteristics of an application page is that it does not support user customization. Therefore, application pages circumvent many of the concerns that site pages have with respect to performance, security and maintainability.
As a SharePoint developer, you should consider application pages as one of the primary building blocks when you are creating business solutions. If you want to get going developing custom application, you should download the sample named CustomApplicationPages which is also available on our downloads page.
First, it is important that you understand exactly what application pages are and how their processing differs from that of site pages. Let's start with an example of an out-of-the-box application page, the standard Site Settings page named settings.aspx. This application page can be accessed from any site, yet it does not support customization. These types of application pages are deployed as physical files on the file system of the front-end Web server in a directory at the following path:
c:\program files\common files\microsoft shared\web server extensions\12\TEMPLATE\LAYOUTS
Note that the physical \LAYOUTS directory is mapped in the IIS metabase to the virtual _layouts directory. This mapping is setup whenever WSS creates a new Web application from an IIS Web site. By using this mapping scheme along with some additional processing logic, the WSS runtime can make each application page accessible within the context of any site in the farm. For example, assume that there are three different sites in a WSS farm accessible through the following three URLs:
http://Litwareinc.com
http://Litwareinc.com/sites/Partners
http://Intanet.Litwareinc.com/sites/Sales
An application page, such as settings.aspx, can be accessed by adding its relative path within the _layouts directory to the end of a site's URL. For example, you can access the Site Setting page by using any of the following three URLs:
http://Litwareinc.com/_layouts/settings.aspx
http://Litwareinc.com/sites/Partners/_layouts/settings.aspx
http://Intanet.Litwareinc.com/sites/Sales/_layouts/settings.aspx
Because there is only one version of an application page scoped at the farm level, it can be compiled into a single DLL and loaded into memory once for each Web application. You never have to worry about the existence of multiple versions of an application page for different sites. Furthermore, application pages are not subject to attack from users who have permissions to customize site pages. Therefore, WSS does not prohibit them from containing in-line code nor does WSS require ASP.NET controls on application pages to be marked within the SafeControl section of the web.config file.
Maybe you never really thought about application pages before in custom SharePoint development before. You might be wondering whether you should use them or not. Here's one reason you should consider using them. Application pages are used extensively by the WSS and MOSS teams to supply much of the standard functionality for provisioning and administrating sites and the elements inside them such as lists and document libraries.
If you open and inspect the source code for many of the standard WSS and MOSS application such as setting.aspx, you will see that they link to a master page in the _layouts directory named application.master. When you create your own custom application pages, you might want to follow suit and create them to link to the application.master file as well. You can alternatively provide your own custom Master Page for your custom application pages to create a custom layout.
What should you take away from this blog post? As a developer creating custom solutions for WSS and MOSS, you should begin thinking about sites pages versus application pages early in the design phase. For each occasion when your solution needs to add another page to a SharePoint site, you should be asking yourself whether you should implement this page as a site page or an application page. Now let's finish with a summarization of why you might prefer one over the other.
The reasons to create pages as site pages
- The page must support customization through Web Parts
- The page must support customization through the SharePoint Designer
- The page must be added dynamically through code or through feature activation
- You must add multiple instances of the page to a site
The reasons to create pages as application pages
- You want to prohibit user customization
- You want to avoid safe mode processing
- You want to achieve the best possible performance