Application Pages: Always ghosted
Site Pages: Ghosted and Unghosted
When site pages ghosted?
LayoutsPageBase is good example. When any page created using this base class (also called layout pages or template pages) and if it is deployed to _layout path or any other path, it has physical presence on file system (c:\program files\common files\microsoft shared\web server extensions\xx\TEMPLATE\LAYOUTS). Then VPP creates instance of page and caches it in database.
When site pages unghosted?
When VPP loads page layouts from content database (instance of page).
What VPP (Virtual Path Provider) does?
VPP does both jobs (Ghosted and Unghosted) for single request of page. First it reads template page (ghosting), second it reads instance of page (unghosting), and then combines both parties and render the page.
Example:
I have a news organization. I have created custom page layout to list down all my news. In my company, the news publisher has responsibility to generate news list page.
mycompanyListPage ----> Provisioned ----> mycompanyListPageA, mycompanyListPageB, mycompanyListPageC
Here, mycompanyListPage is PageLayout and appended A,B,C are page instances created by news publisher using mycompanyListPage template.
I use Module elements to place the template page to particular path and File element to provision instance pages. One more confusing component made MS guys is GhostableInLibrary
<File Url="mycompanyListPage.aspx" Name="mycompanyListPageA.aspx" Type="GhostableInLibrary" />
If you want to provision a page inside a document library then use above line.
<File Url="mycompanyListPage.aspx" Name="mycompanyListPageA.aspx" Type="Ghostable" />
If you want to provision a page from file system (physical path) then use above line. Its like GhostableInFileSystem.
In both the cases mycompanyListPage.aspx is ghostable and mycompanyListPageA.aspx is unghostable.
"WSS Integration with ASP.NET"
chapter from book"Inside Microsoft Windows SharePoint Services 3.0"