How to generate internal link for ContentReference?


If I have a valid ContentReference instance pointing to a block, how can I go about getting the internal URL for that block? Example: ~/link/dd34112844b94401a0c66ed8106ae4cb.aspx

Mar 24, 2022 15:42

I haven't found a method yet that will do it, but this will effectively output the same format:

 var internalUrl = $"~/link/{block.ContentGuid.ToString().Replace("-", "")}.aspx";
Mar 24, 2022 16:20

Hi Ian,

I would be interested in understanding what you are trying to do, why do you want to create a url for a block, as they are not routable?


Mar 25, 2022 20:20

Have a look at my blogpost for varius ways of obtaining the URL.

My favorite:

FROM tblContentLanguage
WHERE fkContentID = 1337
Edited, Mar 26, 2022 18:24

The official way is to use IPermanentLinkMapper to get the PermanentLinkMap from ContentReference (_permanentLinkMapper.Find(contentLink). PermanentLinkMap  contains PermanentLinkUrl which should be what you are looking for :) 

Mar 28, 2022 15:21

@Andrew - The short of it is that I'm allowing editors to link to certain block types from within the Create Link dialog window, which will result in a dynamic modal popup window on the front-end. In doing so, I need to override the UrlResolver so that the correct URLs are generated on both the front-end as well as the Epi admin.

Mar 28, 2022 17:20
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.