This seems to work while browsing the website, but in the CMS admin area, I get the following error:
System.NullReferenceException: Object reference not set to an instance of an object.
This is the line taht causes it:
if (node.ParentNode.ParentNode != null)
But the circumstances under which the error occurs are weird:
1. In Admin, under Pages, select a page that's running this code, click Edit.
2. In Page Editor mode, just click Cancel
3. Click Edit button again, and then you are presented with the error.