Logo Home   Downloads   Up to Bluedog Limited
Ghosted and unghosted pages - part 1 of 2
Posted on 6/6/2004 2:13 AM by Maurice Prather

Have you ever modified a Web Part Page?  If you answered yes, then today’s topic might be of interest.  :)

Each .aspx page is rendered by one of two possible parsers.  When a request is received for an .aspx page, the SharePoint isapi filter determines who will handle the rendering of the page – Asp.net or the SharePoint SafeMode parser.  The first parser, Asp.net, requires the least amount of introduction.  The second parser is unique to Windows SharePoint Services.

The intent of this discussion is to cover the differences between the two parsers.  To be very clear, this discussion applies to pages which come from the main application root of a SharePoint virtual server.  Pages which originate from either the “_layouts” or “_vti_bin” virtual directories can be excluded from the discussion.

As everyone knows, all pages within SharePoint are stored in the database.  This effectively means that for each document, you will find a row in the docs table for that document.  The actual file is stored in the Content column.  This is true for all files.  However, there is one exception - some .aspx pages don’t actually have their content stored in the database.  Instead, these pages reference files which exist on the server’s file system.  These pages are considered ghosted pages.  

From a technical standpoint, ghosted pages are those rows in the docs table which have null values for the Content column and a non-null value for the SetupPath column which points to a file on the file system itself.  The referenced file essentially serves as a template and content source. 

What pages are ghosted?  For example, the default home page is a ghosted page.  Any web part pages created the via New Web Part Page user interface also ghosted.

As you can see, I’ve described ghosted pages as the exception to the rule.  What does it mean if a document doesn’t reference a template on the file system?  Or, more to the point, the Content column actually contains data?  These pages are known as unghosted .aspx pages and they are routed through the SafeMode parser.

What does is the main difference between the SafeMode parser and Asp.net?  Code compilation. 

As everyone knows, Asp.net will parse a page on first render and compile it into an assembly.  The SafeMode parser does NOT compile pages.  It is designed to interpretatively parse a page and create the object structure of the page.  In the event inline server-side code is detected, the SafeMode parser will not allow the page to render.  Additionally, the only objects within the page (i.e. controls marked as runat=server) which can be instantiated are those items found in the SafeControls list.

Can a page transition from a ghosted state to unghosted?  Yes.

Ghosted pages become unghosted once a file has been modified.  If a page is updated using FrontPage 2003, web folders, or the modification of custom document library fields, the Content column of the given document row is populated with the page contents.  All uploaded .aspx files are automatically unghosted.

Are there other differences between SafeMode and Asp.net? Yes.

Although the SafeMode parser was designed to be serve as replacement for the Asp.net parser, it does not offer identical functionality.  The key differences between the two parsers are listed below:

  • SafeMode does not offer AspCompat functionality.
  • SafeMode does not compile; therefore, all compilation directives are ignored.
  • Session State exists; however, in SafeMode once you turn it on, all unghosted pages are forced to participate in Session State.  Unghosted pages do NOT have the option to opt out of using Session State.

    (Update 9/22: Read more about about the implications of turning on SessionState).

Why are there two types of rendering engines?  Security and scalability.

The SafeMode parser ensures unghosted pages are not allowed to run code.  This security feature prevents a user from injecting code into page which may maliciously, or unintentionally, bring down a server, snoop data, etc.  Consider the permission levels associated with updating a page vs. the number of users within a WSS server – if you’re the admin, you would probably be extremely wary of giving anyone the “Add and Customize Pages” right knowing that they would be able to freely execute server-side code if the SafeMode parser didn’t exist.  With our current behavior, once a page is transitioned from a ghosted to unghosted state, the admin knows that page cannot influence the behavior of the server.

Additionally, without the SafeMode parser, all pages would have to be routed through Asp.net which would mean all pages would be compiled and their associated assembly loaded into memory.  Imagine a site with thousands of operational pages...  the memory requirement would be huge.   The current design limits page compilation to a very small number of pages relative to the actual number of pages within a WSS-extended virtual server.

I'll post the second part of this discussion in a short while...

-Maurice

====
Series articles:
Post 1/2 - you're reading it!
Post 2/2 - http://www.bluedoglimited.com/SharePointThoughts/ViewPost.aspx?ID=5
 
re: Ghosted and unghosted pages - part 1 of 2
OK. Good information but application would help me understand better. But maybe you can tell me if this does the trick:
 
I need to modify a default.apsx file for Project Server.
I loaded it from the common files on web server. When it loaded there are no items in the list in the quick launch bar. This I assume references that it is ghosted. I then opened the default.aspx from a site created by Project server. I made some changes in FP and saved it. I then copied it from the explorer view of the website to the web servers location. The Quick Launch bar reset but the rest of the content did not. My guess is that this is now unghosted?
 
I am able to reset the default on the web server to its original design by copying the file from the back up.
 
Is this behavior what you are pertaining to. If so - then I understand. If not could you provide a working mans example?
 
Thanks
Greg 
Greg McAllister @ 7/21/2004 4:18 PM
re: Ghosted and unghosted pages - part 1 of 2

I’m not familiar with Project Server and therefore won’t try to extrapolate on your example.

Let’s look at a WSS/SPS example…

  1. Go to Create | Web Part Page.  The page you create is “ghosted”.
  2. Open the page in FrontPage. 
  3. Make a change and hit save.  Your page is now “unghosted”.

Difference between #1 and #3?  Huge.

In #1, the ghosted page is basing its content from the template which exists on the file system.  The asp.net parser renders the page.

In #3, the unghosted page content is taken from the database.  When you saved the page in FP, the "template" contents from #1 were copied over to the database. All future versions of that page are now based off the database copy, not the file system copy. The page is now controlled by the SafeMode parser.

Once you transition a page from a ghosted to unghosted state, the page cannot be returned to the ghosted state.  More info in the follow up post (part 2 of 2 - http://www.bluedoglimited.com/SharePointThoughts/ViewPost.aspx?ID=5).

Maurice Prather @ 7/21/2004 10:21 PM
re: Ghosted and unghosted pages - part 1 of 2
hello,
thank you for the article. I got one question: You wrote, that SafeMode don't supports Aspcompat, but I'm using a DSO-Object in my ASP.Net webcontrol so I have to use aspcompat =true. Is there a workaround for the missing aspcompat-switch?
 
 
mehmet yalcin @ 1/28/2005 12:39 AM
re: Ghosted and unghosted pages - part 1 of 2
Unfortunately, there is no workaround other than to perhaps place your page in _layouts.
Anonymous User @ 3/9/2005 8:36 PM
re: Ghosted and unghosted pages - part 1 of 2
I created custom Web Part Page Templates following the example of MSDN (see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_sp2003_ta/html/sharepoint_creatingcustomwpptemplates.asp). I was able to follow and test the example fine by creating pages from the custom templates I created. Actually I only created one template by copying one of the custom aspx templates that came with the sample as described in the MSDN document.
 
The problem is that the pages I create from my custom template are unghosted. I expected the pages to be ghosted because I did not modify the created pages (for example, I did not edit it in Frontpage to cause it to be unghosted). I use the GhostHunter Web Part found in the SP Products and Technologies resource kit to determine ghosted vs. Unghosted. For comparsion, I created pages using the default page creation form and as expected, the resulting page is ghosted.
 
Does anyone know if the custspcf.aspx page that comes with the sample inherently cause pages to be created unghosted? Are there places I should check in my customization that may be causing the problem?
 
I appreciate any help.
Daryl Rudolph @ 3/29/2005 2:54 PM
re: Ghosted and unghosted pages - part 1 of 2
Daryl,
 
Pages created using the custom templates sample are unghosted.  You haven't done anything wrong; it's just how the pages are created. 
 
-Maurice
 
 
Anonymous User @ 3/29/2005 9:34 PM
re: Ghosted and unghosted pages - part 1 of 2
Thanks Maurice. I guess now my question is whether there is a way (an example) to create custom templates so that the resulting pages are ghosted?
 
I compared the code in custspcf.aspx with the standard spcf.aspx code and saw that the code is very different. From what I could tell most of the functionality for spcf.aspx to create the page must be encapsulated in _vti_bin/owssvr.dll as this is the action for the form 'frmWebPage' that is submitted when OK is clicked.
 
No closer to an answer. Just an observation.
 
Thanks!
 
Daryl
Daryl Rudolph @ 3/30/2005 6:49 AM
re: Ghosted and unghosted pages - part 1 of 2
There is a way to create ghosted pages.  I'll post a how-to in the coming days.
 
-Maurice
Maurice Prather @ 4/4/2005 9:33 AM
re: Ghosted and unghosted pages - part 1 of 2
Maurice, I was just wondering if you were still planning on posting the how-to for creating custom web part pages that are ghosted?  We have a need to do down this path, and I would prefer to be able to keep these pages ghosted. 
 
Thanks!
-Brent
Brent @ 5/4/2005 9:51 AM
re: Ghosted and unghosted pages - part 1 of 2
Maurice Prather @ 5/9/2005 10:03 PM
Need some Help.... Please....
Hi....
 
I would really appreciate some help.... Ghosting and unghosting has always been a sort of dilema for me. I just want to clarify..... is a page only unghosted when using frontpage... How about if I edit the default.aspx (Homepage) in Notedpad does this unghost the page as well?
 
Also, when I add new columns to a list does it become unghosted? When I modify a page only through the browser and add like 10 new webparts does it become unghosted?
 
Would greatly appreciate your help.....
 
Thanks .....
 
 
Ryan @ 10/5/2005 1:00 AM
re: Ghosted and unghosted pages - part 1 of 2
Is there way to run code on unghost page besides using web parts?  I want to develop a survey with 30 pages.  I don't want to build 30 web parts.
Anonymous User @ 10/29/2006 6:16 PM
re: Ghosted and unghosted pages - part 1 of 2
Unghosted pages cannot have inline code.  If you want to run code, you will need to create controls, web parts or use a shim technology such as the SmartPart.
Maurice Prather @ 11/1/2006 10:10 AM
Unghoted page issues
Hi Maurice
 
I am new to SPS/ WSS. I have done abit of research on how to deploy our Intranet. It is clear to me that I want to use unghosted pages wherever possible (if not everywhere) primarily to get the benefits of being able to update the look of the site by editing the site definitions.
As I understand it there are many ways to unghost a page including using the browser.
 
How can this be managed?
Am I being realistic in my deployment strategy?
 
If not, how do you manage cross site updates eg site look and feel?
 
Thanks in advance
 
Ian B 
Ian @ 12/3/2006 12:59 PM
re: Ghosted and unghosted pages - part 1 of 2
Ian,
 
Managing page state is possible with the proper management of permissions and expectations.  Browser-induced changes are not nearly as prevalent as you may think; especially when you start folding in page and/or list modification permissions.
Maurice Prather @ 12/7/2006 10:11 AM
re: Ghosted and unghosted pages - part 1 of 2
Hi,
 
Somebody help me in solving the below issue regarding unghosting of a page in sharepoint.
 
A sharepoint .aspx page having a custom control loads fine initially.  When the page is unghosted it gives the error as "web patt or web form control no this web page cannot be displayed or imported because it is not registered as safe control".  As we all know it is a common error but the custom control is added as safe control in the web.config.  Another thing is this error comes only for our trial server.  The same control is working fine in dev and production servers
 
Please share with me any ideas on how to investigate the issue.  I've even tried reinstalling sharepoint
madhu @ 5/17/2007 4:24 AM
Microsoft Certified Master
Are you looking for a team of SharePoint experts?
ShareSquared can help ... drop us a note.
 
 
ShareSquared, Inc.
MVP Logo
Keyword Search
 
View by category
 

Disclaimer:
The contents of this site represent thoughts and opinions of the authors , not those of anyone else - such as past, present and future employers.  This a forum of the exchange of ideas centered on SharePoint technologies.  It is not a support channel.  :)

Copyright © 2004-2009 BluedogLimited.com. All rights reserved.