Content items locations API

The article describes how Sitefinity CMS resolves content locations. It explains what ContentLocationService is, how to use it, and what problems can you solve with it. It clarifies what are a locations and their priority, and how you can set them.

Sitefinity CMS comes with a service called IContentLocationService. It gives you the ability to know the locations of an item in the system – these are the actual URLs of a content item in the context of the pages where it is displayed. Each Sitefinity CMS content widget uses the service to register the location of the content item on the page. For example, if you have a News widget on a page from your site, after you publish the page, Sitefinity CMS knows that on this page you have a widget capable of displaying content of type News. It also knows the exact content items that the News widget is configured to display. IContentLocationService API is also used internally to bring several key benefits to the product:

  • Generating the Preview location of a content.
    When you edit a content item and click on the Preview button, Sitefinity CMS displays this item in the context of the page where it is used, loading the page content and styles, thus allowing you to see how your content is going to look like on the page, once you publish it.
  • Listing the pages where an item is published.
    All content modules now have the option to show a list of pages where the type of content is published. You can see the list and modify the priority of the pages.
  • Provide a canonical URL tag for content items.
    The first location in the list of pages where an item is published is the canonical (default) location. The Sitefinity CMS widgets includes a rel="canonical" parameter when generating the link to the item, thus ensuring proper SEO.

    IMPORTANT: The default location of an item must be a page that is accessible by all users, that is, they have permissions to view it.

  • Generating the search results.
    You do not have to specify a default page where a content type is published when you create your search index. Sitefinity CMS uses the IContentLocationService API to resolve the default page where an item is shown and uses this information to build the link to this item in the search results.

Want to learn more?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?