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!

EPiServer 9 StaticLinkURL

Vote:
 

Hi,

We've been taking out the "actual" uri from pages, i.e. the one that the public see's when they browse the website - but when EPiServer 9 came out, we're getting links back which looks something like this "/link/db120a2414964372b41879e8e03433bd.aspx" instead.

The URI we used to get:

/campaigns/alloy-track---get-the-whole-team-involved-in-the-project/

The URI we get now:

/link/db120a2414964372b41879e8e03433bd.aspx

We're still using the same code in which we basically just take out StaticLinkURL from a EPiServer.Core.PageData object.

I've been looking through the PageData object to see if it was moved somewhere, but LinkURL contains the same (albeit with extra parameters, e.g. epslanguage).

I've found something that's close to it, namely URLSegment, but that's still just "alloy-track---get-the-whole-team-involved-in-the-project" which isn't enough.

I've also tried reading the changenotes but I've failed to find anything regarding this, does anyone have a clue what may be causing this? Or where it was moved to?

By the way before you ask, the result we used to get didn't depend on wether they had friendly or not, we'd always get whatever they had - again, the public url.

Thanks in advance,

Mattias

#143542
Jan 26, 2016 16:03
Vote:
 

var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>();

var url = urlResolver.GetUrl(contentReference, language);

#143543
Jan 26, 2016 16:27
Vote:
 

Thank you Daniel,

However, I can't put this into context.

We're doing this from a webservice, i.e. it has no connection to visiting the pages in question, we're getting these pages using the following order (pseudocode):

PageDataCollection children = DataFactory.Instance.GetChildren();

PageDataCollection langBranches = DataFactory.Instance.GetLanguageBranches();

foreach (PageData page in langBranches)

Here, the PageData object contains these strange urls (while they do redirect to the correct page, it's not the ones we're looking for).

Thanks,

Mattias

#143546
Jan 26, 2016 16:40
Vote:
 

Apparently StaticLinkURL seems to be correct, it's supposed to be "/link/randomhash".

The issue seems to occur in the following statement:

UrlRewriteProvider.ConvertToExternal(ub, page.PageLink, System.Text.UTF8Encoding.UTF8);

Comparing EPi8 to EPi9, this is where it becomes the true external URI, while in EPi9 it remains as "/link/randomhash".

Code:

if (page.LinkType != PageShortcutType.External)
{
	UrlBuilder ub = new UrlBuilder(UriSupport.Combine(hostUrl, page.StaticLinkURL + "&epslanguage=" + page.LanguageBranch));
	UrlRewriteProvider.ConvertToExternal(ub, page.PageLink, System.Text.UTF8Encoding.UTF8);
	path = ub.Path;
}

Where path in this case becomes the true external URI.

I can't understand why it works in all previous versions of EPi but not EPi9, any help is appreciated.

#143581
Jan 27, 2016 9:37
Vote:
 

They've changed a lot in that part. UrlResolver is your new best buddy for creating external urls basically. The rest is legacy code that might work still and will probably be removed in the future. 

You can also check out

http://world.episerver.com/Forum/Developer-forum/-EPiServer-75-CMS/Thread-Container/2014/4/Get-friendly-Url-from-Url-property/

#143641
Jan 28, 2016 10:38
Vote:
 

Thank you Daniel, that helped.

For anyone else who previously used UrlRewriteProvider and is having problems, the fix is embarrassingly easy:

path = UrlResolver.Current.GetUrl(page.PageLink, page.LanguageBranch);

Instead of:

UrlBuilder ub = new UrlBuilder(UriSupport.Combine(hostUrl, page.StaticLinkURL + "&epslanguage=" + page.LanguageBranch));
UrlRewriteProvider.ConvertToExternal(ub, page.PageLink, System.Text.UTF8Encoding.UTF8);
path = ub.Path;

However, I am slightly unsure if this will handle them as UTF8 automatically (hence System.Text.UTF8Encoding.UTF8).

EDIT: Just tested it, seems to work just fine.

#143680
Edited, Jan 28, 2016 18:29
Vote:
 

Sweet!

#143691
Jan 28, 2016 23:10
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.