Resolve dynamic links

Overview

Sitefinity CMS enables you to automatically update the references you make from your content item to other content - media or pages - thus avoiding the need to update links manually every time referenced content is modified. As a result, there are no outdated content references and broken links.

For example, if your content item links to an image, Sitefinity CMS automatically resolves every reference to this image even after modifications such as changes in title, address, or even replacement with another image are done. 

To correctly retrieve and persist content from and to the database, Sitefinity CMS includes an sfref attribute to the HTML tag of the referenced content. The sfref attribute holds important information - the Guid of content item you are referencing to and, depending on the type of content item, the following:

Content type sfref attribute
Images [images|providername]image_id
Documents
[documents|providername]document_id 
Videos
[videos|providername]video_id 
Pages [rootNodeId]page_id

When you create a content item that links to other content or pages, this content item is persisted to the database. As a result, Sitefinity CMS injects the value of the sfref attribute as a value of the src attribute of the HTML tag of the content that you saved to the database. Upon retrieval from the database, Sitefinity CMS resolves this content item using a link parser. The DynamicLinkParser class in Sitefinity CMS is a Helper class for resolving and unresolving dynamic links in HTML formatted text. Depending on where you view the item from, the sfref attribute is resolved differently:

  • Backend:
    Both the src and sfref attributes hold their respective values. The sfref in the backend is used by Sitefinity's designer dialogs. When you open an image in the backend using a designer, the sfref attribute locates the correct content item to be opened in the designer mode.
  • Frontend:
    The sfref attribute is omitted, so that it does not inflate the HTML with unnecessary information.

Resolve dynamic links programmatically

If you choose to implement your own logic for displaying HTML content of content items, you must resolve all links to other content - media or pages. To do so refer to the following example:

In the code above, you get an instance of the DynamicLinksParser class and call the Apply method. As a result all dynamic links in the specified HTML text are resolve to point to their actual location. When creating the DynamicLinksParser class instance, you can pass constructor parameters to remove the sfref attribute from the HTML and resolve URL's with their absolute path.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?