How to determine the domain of a link on a page

kentico team nextscape asked on December 5, 2022 14:23

Thank you as always

Kentico version is 12.0.95, PortalEngine. The main Transformation used is the ASCX format. The Kentico portal has three sites.

I am having a very difficult time and I wonder if you could give me some advice.

In Transformation, is there any way to determine whether the page is a link to a page on another site or a link to a page on the current site? And what code should I write to determine this? It can be a custom method in Transformation if that can be achieved.

I have looked at the 'General' tab on each page of the Page application, for example, but I can't find any clues to determine this.

If I could get the 'Name' or 'Site' of the General->Linked page in the Page application, I would be able to use those data to determine this, but if that is not possible, I can use other methods.

Correct Answer

Juraj Ondrus answered on December 7, 2022 13:38

The best would be switching to text transformation and use the current page - e.g. CurrentPageInfo macro which gets cached. So you can get the {%CurrentPageInfo.NodeSiteID%} value from cache and if you do not have hundreds of sites, you can use simple macro condition. Or, you can also use {%CurrentDocument.Site.SiteDomainName%} - but this is not in the page info cache, so there are calls made to the DB.
Or, if you are using linked pages from other sites, again using macros is easier and instead of creating custom ASCX transformation methods, you could have already rewritten the code to text transformation and use macros:
{% CurrentDocument.NodeLinkedNode.NodeOriginalNode.Site.SiteDomainName #%}
and others...

0 votesVote for this answer Unmark Correct answer

Recent Answers


Juraj Ondrus answered on December 6, 2022 06:39

You would need to create a custom transformation method and use C# code to parse the link's HTML and check the domain name part.
However, if you mean linked pages feature in Kentico, then these pages can be linked within the same site or from other sites within the same Kentico instance.
So, again you will need to use some C# and Kentico API to get the tree node object, e.g. by the AliasPath and check the NodeSiteID or NodeORiginalNodeID values to see where the tree node object belongs.
Please see the pages database structure docs and then check the columns of those tables in the SQL Management studio to get familiar with the tree node object and you will find what you are looking for.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on December 7, 2022 13:24

How are the links/URLs being input by the user? If the URL is relative, you could assume it's local URL or one on the current site. If it has it starts with http then you could assume it's external or not on the current domain.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on December 7, 2022 13:53 (last edited on December 8, 2022 15:57)

I agree Juraj, however a simple IF statement could be logical enough depending on the users needs.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.