I've got a method that returns the top level alias path. Maybe this might help.
/// <summary>
/// Gets the top level navigation from a URL
/// </summary>
/// <param name="URL"></param>
/// <returns></returns>
public static string GetParentAlias(string URL)
{
// putting a dummy value in so if it cannot get a URL it will return one that doesn't exist and not display any items.
string ReturnValue = "/unknown";
// parse out the URL and get only the text between the first / and the second /
int firstIndex = 0;
string urlFirstSlashRemoved = URL.Substring(1, URL.Length - 1);
if (urlFirstSlashRemoved.Length > 0)
{
// check for second level page ie: /page1/page2/
firstIndex = urlFirstSlashRemoved.IndexOf("/");
if (firstIndex > -1)
{
ReturnValue = "/" + URL.Substring(1, firstIndex);
}
else
{
// parent page
ReturnValue = URL;
}
}
return ReturnValue;
}