Sitefinity Page
URL's are Guids

May 19

For as long as I have been using Sitefinity I have never come across this scenario. A custom or dynamic long text field where the selected Sitefinity page URL renders out as a GUID. Turns out, that I should have always had a utility function wrapping my fields before I render them out.

The scenerio occurs when using a custom field and the Html editor. In the editor you can create hyperlinks. One of the options is to select an existing Sitefinity page. (Thats been around since SF 4.0) This creates a anchor tag with a custom sitefinity attribute of the page. This is quite cool becuase it means that if you move the page this link will still work.

To render this on a page you should use the @Html.HtmlSanitize(). Or you may be using @Html.Raw(). Whats the difference? The Sitefinity sanitiser option checks and sanitises the HTML. Especially important for any user submitted HTML. The 'Raw' option literally just renders out what is there.

But both of those options will fail to render the href attribute of the Sitefinity page links that the content editor selected. It will instead render it as a guid.

So yes, I had this senerio and funny enough it was never an issue. Turned out the users had never, over the past 18 months selected a Sitefinity page.

To fix it I needed to write a helper to resolve the links.

public static class GetHtml
{
    public static String ResolveHtml(String sfHtml)
    {
        DynamicLinksParser dynamicLinksParser = new DynamicLinksParser(falsetrue);
        return dynamicLinksParser.Apply(sfHtml);
    }
}

Makes sense as I think about it now. Though I thought the Sitefinity sanitiser method would have auto included this resolver. None teh less, the above code will help you ensure all those links are rendered correctly.

FYI: You can look to extend the sanatiser in Sitefinity.


Darrin Robertson - Sitefinity Developer

Thanks for reading and feel free to comment - Darrin Robertson

If I was really helpful and you would buy me a coffee if you could, yay! You can.


Leave a comment
Load more comments

Make a Comment

recapcha code