SaaS CMS has officially launched! Learn more now.

Fully qualified URL + EpiServer Content Delivery API

Vote:
 

Hello,

I have this issue which I can't figure out what it is:

Based on EpiServer articles I am using a CustomContentModelMapper and overriding below method to get fully qualified urls in Content api resonse.

protected override string ResolveUrl(ContentReference contentLink, string language)
{
string resolvedUrl;
if (_urlResolver == null)
{
resolvedUrl = _urlResolverService.ResolveUrl(contentLink, language);
}
else
{
resolvedUrl = _urlResolver.GetUrl(contentLink, language, new UrlResolverArguments()
{
ContextMode = ContextMode.Default,
ForceCanonical = true
});
}
return string.IsNullOrEmpty(resolvedUrl) ? null : UriSupport.AbsoluteUrlBySettings(resolvedUrl);
}

However for some reason, in my integration enviroment, I see some urls (like image url etc) still coming as reference url and not fully qualified. Pre production and Production environments are working fine as expected.

I am not sure what is it that is causing issue in integration environment. Any thoughts what I could check. Also is there a way to ignore the port number from the fully qualified url.

#221711
Apr 23, 2020 18:54
Vote:
 

Hi Dileep,

I have used Uri class constructor to create a qualified URL, try this way.

var url= _urlResolver.GetUrl(contentLink);
var qualifiedUrl= new Uri(SiteDefinition.Current.SiteUrl, url);
#221730
Apr 24, 2020 2:41
Dileep D - Apr 28, 2020 21:06
Sanjay,
Thanks for inputs. I will try this out but my question was more around why the same code works in one DXP environment vs other DXP environment. Any setting that I may have changed or something.
Vote:
 

Hi, 

The 'ForceCanonical = true' setting does not guarantee that you always get an absolute Url. Even with this setting set to true, UrlResolver still depends on other settings (i.e: the hostname, the current site of content, etc ...) to decide which type of url (relative/absolute) should be returned. So maybe some hostname setting of your Integration environment differs from your Pre and Production environment. 

If you want the API to always returns absolute Url, you can check if the _urlResolver.GetUrl() return a relative Url or not, then prepend the relative Url with the hostname.

#224974
Jul 01, 2020 8:57
* 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.