URLHelper.GetAbsoluteUrl not returning domain name

Tony Perry asked on November 26, 2021 14:18

Hi,

Got a strange one with URLHelper. Locally this is returning the domain name for my site, but in another environment (same version of Kentico), the domain is not being returned.

With the following code as an example:

var url = URLHelper.GetAbsoluteUrl("/booking");

locally I get https://mysite.local/booking

in the UAT environment, the same code is producing /booking without the domain in front of it. I see there is an overload, to provide the domain name, but am puzzled why that's needed when it works locally. I know, I know....works on my machine!

TIA

Tony

Correct Answer

David te Kloese answered on December 6, 2021 10:28

I'd recommend to reach out to Kentico Support (support@kentico.com) as they are able to more accurately tell you the inner working of the methods. As you said most likely it's related to environmental setting, access restriction or something similar.

0 votesVote for this answer Unmark Correct answer

Recent Answers


David te Kloese answered on November 26, 2021 16:20

I recall seeing something like this.. but can 't remember what the issue is.

First off do you really need the absolute url? As relative should work when used on the site obviously...


few things to check

  • Can you compare the settings (URL and SEO), but also the settings on the SITES application for the given site.

  • Could it be related to having multiple cultures or sites that are not present on your local instance?

  • valid SSL certificates for the UAT instances?

  • where do you get the input for that path string?

0 votesVote for this answer Mark as a Correct answer

Tony Perry answered on November 26, 2021 16:44

Hi David,

Thanks for taking the time to respond. To answer your questions......

I need the full URL as this is for an openGraph meta tag to allow an image to be referenced on something like twitter etc.

SEO/URL settings in both environments are the same, there is only one site and one culture in both environments and UAT has a valid SSL certificate. Locally we are using a self cert SSL.

The input path is coming from a TreeNode object

Tony

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on November 29, 2021 13:18

Makes sense..

As I've seen some odd stuff for urls, is your local instance on an actual url pointing to your machine or on a "localhost" type of url?

are you using the actual URLHelper.GetAbsoluteUrl method or are you getting the property from the Node: TreeNode.AbsoluteURL?

As for the latter it could be you're not selecting enough data for the Node (e.g. the correct document version, culture, etc.)

0 votesVote for this answer Mark as a Correct answer

Tony Perry answered on December 6, 2021 09:57

Hi David,

Sorry for the slow response.......

So I have no idea what is going on with this, the code went live (accidentally) last week, and the code is working fine in prod, so must be an environmental thing that we will need to track down, which is annoying. Thanks for you time with this

Tony

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.