How to redirect all linked pages (documents) to their respective main pages from code-behind?

Greg Laycock asked on May 10, 2017 22:03

I have a large number of linked pages (documents) on a site which I thought were in accessible, but now realize there are ways in which they can be visited. I need to redirect each of them to the main page from which it was cloned (linked). There are too many of them to individually redirect via the CMS, and more will be added, so that's not fool-proof enough. All of these pages share the same ASPX template, however, so I'm trying to determine a way to check to see if the page is a linked page (by looking at the NodeLinkedNodeID) in the code-behind and then redirect it if so. I've found a number of potential ways to do this, but none work from the code-behind. Any ideas?

Kentico 10.0.19 ASPX Templates + Portal

Correct Answer

Greg Laycock answered on May 10, 2017 23:31

The following seems to work all right, but it doesn't take into account the site. Any other ideas?

if (DocumentContext.CurrentDocument.NodeLinkedNodeID > 0)
1 votesVote for this answer Unmark Correct answer

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