K13 Get node/document/page from live url

Rory Aherne asked on July 16, 2026 13:35

Hi,

I have a scenario where I need to get a document and the only info I have is the live url. In my particular scenario, the page alias and the url slug are different. I'm not talking about an alternative url. Here a page was created with a node alias like '/document' but the url slug was changed to /my-document.

I have a million ways to get from a path, node guid, pageid, nodeId, etc, to get to the live Url but can't seem to be able to do it in reverse.

For now, I've manually updated the page alias but that's having knock on effects so I'd rather leave the original page alias in place in the future.

I'm on v13.0.188

Thanks,

Rory

Correct Answer

Lorenzo Virreli answered on July 18, 2026 12:18

Method 1: Using Page Url Path Info Provider (Recommended) You can query the Page Url Path Info Provider to find the mapping for the URL path, which will give you the Node ID. From there, you can easily fetch the actual document.

C# using CMS.DocumentEngine; using CMS.Webpages;

// 1. Clean the relative URL path (e.g., "/my-document") string urlPath = "/my-document";

// 2. Get the URL path info matching the slug var pathInfo = PageUrlPathInfoProvider.GetPageUrlPaths() .WhereEquals("PageUrlPathUrlPath", urlPath.TrimStart('/')) // Kentico stores paths relative without leading slash typically, or use standard cleaning .TopN(1) .FirstOrDefault();

if (pathInfo != null) { // 3. Retrieve the page using the NodeID found TreeNode page = new DocumentQuery() .WhereID("NodeID", pathInfo.PageUrlPathNodeID) .LatestVersion(false) // Set to true if you need the edited version in Kentico admin .Published(true) .FirstOrDefault();

if (page != null)
{
    // You now have your document/page object
}

} Method 2: Direct DocumentQuery Extension If you prefer a more direct approach, you can join your document query with the URL path table (CMS_PageUrlPath) using standard Kentico DataQuery APIs:

C# using CMS.DocumentEngine; using System.Linq;

string urlPath = "my-document"; // Path without leading slash

var page = new DocumentQuery() .Source(s => s.Join("CMS_PageUrlPath", "NodeID", "PageUrlPathNodeID")) .WhereEquals("PageUrlPathUrlPath", urlPath) .LatestVersion(false) .Published(true) .FirstOrDefault(); Key Considerations: Sites: If you are running a multi-site environment, make sure to add .OnSite("YourSiteName") to your query or filter the Page Url Path Site ID to avoid conflicts if the same slug exists on multiple sites.

Culture: If the slug is culture-specific, you may also want to filter by or ensure the Document Culture matches your requirements.

ALSO VISIT THIS: https://altrixcalculator.com/

0 votesVote for this answer Unmark Correct answer

Recent Answers


Rory Aherne answered on July 20, 2026 14:13

@Lorenzo Virreli you put me on the right path (pun very much intended!)

var currentCultureCode = LocalizationContext.CurrentCulture.CultureCode;
var siteId = await _siteRepository.GetSiteIDAsync();
var pathInfo = PageUrlPathInfoProvider.GetPageUrlPathInfo(path.TrimStart('/'), currentCultureCode, siteId);
0 votesVote for this answer Mark as a Correct answer

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