Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Redirect to a URL set by a URL property field.

Vote:
 

I have a custom block, with a URL field.  (EpiServer.Url) 

In the editor, I go to the properties and set the page from other pages in the site.  In this case, "Contact Us".  (site path, "/en/contact-us")

But when the controller gets the path, it looks like this: "/link/03b82dc1edc34762bfa4575c24180166.aspx?id=373&epslanguage=en", not "/en/contact-us".

What do I do to get the real path.

#121567
May 13, 2015 23:05
Vote:
 
#121568
May 14, 2015 0:03
Vote:
 

This should work

var urlHelper = ServiceLocator.Current.GetInstance<UrlResolver>();
var friendlyUrlBuilder = new UrlBuilder(<!----Your url string here -->);
ContentReference contentReference = PermanentLinkUtility.GetContentReference(friendlyUrlBuilder);
 string url = urlHelper.GetUrl(contentReference);
 
return url;
#121573
May 14, 2015 10:42
Vote:
 

var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>();
var pageUrl = urlResolver.GetUrl(contentReference, cultureName);

In a cshtml view
try
<a href="@Url.ContentUrl(EPiServer.Url)">
or
@Html.UrlLink(EPiServer.LinkUrl)

#121574
Edited, May 14, 2015 11:57
Vote:
 

You can get real path using UrlHelper

var urlHelper = ServiceLocator.Current.GetInstance<UrlHelper>();
var url = urlHelper.ContentUrl(currentBlock.Link);
#121576
May 14, 2015 12:16
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.