Retrieving the URL to an EPiServer page seems like a basic thing to do, but it’s not quite obvious…
Referring to a page is normally represented by an instance of the PageReference class, so obviously that contains a public property called Url or something, right?
Wrong!
Instead, this is how to do it (as a bonus I also show how to retrieve the PageReference from a page property):
string url = ""; PropertyData pd = CurrentPage.Property["Shop_CartPage"]; if (pd != null && pd.IsNull == false) { PageReference pageref = (PageReference)pd.Value; url = GetPage(pageref).LinkURL; }
If anyone knows better or more efficient ways to do this, please add a comment to this post 🙂