How to generate internal link for ContentReference?

Ian
Ian
Vote:
 

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

#277080
Mar 24, 2022 15:42
Ian
Vote:
 

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";
#277082
Mar 24, 2022 16:20
Vote:
 

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?

Andy

#277208
Mar 25, 2022 20:20
Vote:
 

Have a look at my blogpost for varius ways of obtaining the URL.
https://www.gulla.net/no/blog/content-url-with-or-without-shortcut/

My favorite:

SELECT LinkURL
FROM tblContentLanguage
WHERE fkContentID = 1337
#277245
Edited, Mar 26, 2022 18:24
Vote:
 

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 :) 

#277341
Mar 28, 2022 15:21
Ian
Vote:
 

@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.

#277342
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.